以下代码签名消息带有恢复,如何使用C#BouncyCastle实现?
std::vector<unsigned char> data{ 1,2,3,4,5,6 };
CryptoPP::AutoSeededRandomPool rng;
CryptoPP::InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 2048);
CryptoPP::RSA::PrivateKey privateKey(params);
CryptoPP::RSA::PublicKey publicKey(params);
CryptoPP::RSASS<CryptoPP::PSSR, CryptoPP::SHA1>::Signer signer(privateKey);
CryptoPP::SecByteBlock signature(signer.MaxSignatureLength(data.size()));
unsigned long signatureLen = signer.SignMessageWithRecovery(rng, &data[0],
data.size(), NULL, 0, signature);
std::vector<unsigned char> encrypted;
encrypted.assign(signatureLen, 0);
memcpy(&encrypted[0], signature.m_ptr, signatureLen);
答案 0 :(得分:3)
我认为Iso9796d2PssSigner
命名空间中的Org.BouncyCastle.Crypto.Signers
类应该可以做你想要的。您可以在ISO9796Test.cs的源代码中找到使用示例。