1
我正在获得“RSA/OAEP-MGF1(SHA- 1):当密文长度为154时,该密钥的长度为192“,当我尝试解密使用crypto ++库的加密会话密钥时。在解密会话密钥时出现异常“RSA/OAEP-MGF1(SHA-1):密文长度154与该密钥的所需长度192不匹配”
以下是相同的代码片段:
std::string encrypt_session_key(PAES_KEY_WITH_IV pKey)
{
std::string ciphered;
CryptoPP::SecByteBlock block(pKey->key.size());
try {
CryptoPP::RSAES< CryptoPP::OAEP<CryptoPP::SHA> >::Encryptor enc(RSA_master_pubKey);
enc.Encrypt(rng, pKey->key, pKey->key.size(), block);
ciphered.assign((char *)block.BytePtr());
}
catch (const CryptoPP::Exception& e)
{
std::cerr << e.what() << std::endl;
b_success = false;
}
return ciphered;
}
PAES_KEY_WITH_IV decrypt_session_key(std::string & ciphered)
{
CryptoPP::SecByteBlock rec(ciphered.size());
CryptoPP::SecByteBlock block((const byte *)ciphered.data(), ciphered.size());
PAES_KEY_WITH_IV pKey = new AES_KEY_WITH_IV;
try {
CryptoPP::RSAES< CryptoPP::OAEP<CryptoPP::SHA> >::Decryptor dec(RSA_master_privKey);
dec.Decrypt(rng, block, block.size(), rec);
pKey->key = rec;
}
catch (const CryptoPP::Exception& e)
{
std::cerr << e.what() << std::endl;
b_success = false;
}
return pKey;
}
在这里,我已经给了加密和解密的会话密钥两种代码。
有人可以告诉我为什么我得到以上异常?
请注意:我正在使用crypto ++库的5.6.3版本。
在此先感谢。
将所有字节的大小分配给字符串后感谢,我可以解决此问题。 – user3752324
现在我没有得到任何异常,但是你能告诉我为什么原始和解码的会话密钥不一样吗? – user3752324
最后字节差异 – user3752324