所以我有这段代码:
BlueSOD::Encryption::DecryptionData BlueSOD::Encryption::EncryptionFactory::OpenEnvelopeDecrypt(DecryptionWork && work)
{
EVP_PKEY* privateKey = work.privateKey.get();
auto eKey = (unsigned char*)work.aes_info.key.c_str();
auto eIV = (unsigned char*)work.aes_info.iv.c_str();
EVP_CIPHER_CTX_ptr cipherCtxPtr{ AcquireCipherCtx() };
EVP_CIPHER_CTX* cipher = cipherCtxPtr.get();
int status;
status = EVP_OpenInit(cipher, m_Cipher, eKey, work.aes_info.key.size(), eIV, privateKey);
CheckForError(status);
auto decrypted = make_unique<unsigned char[]>(work.cipherText.size() + EVP_MAX_BLOCK_LENGTH);
auto cipherTemp = (unsigned char*)work.cipherText.c_str();
int amtDecrypted = 0;
int bufferLength = 0;
status = EVP_OpenUpdate(cipher, decrypted.get(), &amtDecrypted, cipherTemp, work.cipherText.size());
CheckForError(status);
bufferLength += amtDecrypted;
//error occurs in both versions of the following code
//status = EVP_OpenFinal(cipher, decrypted.get() + amtDecrypted, &amtDecrypted);
status = EVP_OpenFinal(cipher, decrypted.get(), &amtDecrypted);
CheckForError(status);
bufferLength += amtDecrypted;
DecryptionData data;
data.plainText = CreateSecureString(decrypted.get(), bufferLength);
return move(data);
}
当我在调试器decrypted
中逐步执行它时,在调用之前保持正确的纯文本,但EVP_OpenFinal
返回标题中的错误。上面的代码就是我最初的代码(并返回相同的错误)。
EVP_OpenFinal
在调用前decrypted
保存正确的纯文本时,~/.invoke
返回错误的原因是什么?