与@Jon 相同的方法,有点简化
std::string ciphertext = "..."; // what Python encryption produces
std::string decryptedtext;
byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ];
// populate key and iv with the correct values
CryptoPP::CBC_Mode< CryptoPP::AES >::Decryption decryptor;
decryptor.SetKeyWithIV(key, sizeof(key), iv);
CryptoPP::StringSource(ciphertext, true,
new CryptoPP::StreamTransformationFilter( decryptor,
new CryptoPP::StringSink( decryptedtext )
)
);
true
参数 to表示“CryptoPP::StringSource
消耗整个输入”
请注意,(显然)您需要 C++ 解密器才能知道用于加密的 IV。由于您在 python 中生成随机 IV,因此流行的技术是将 IV 预先添加到加密文本中。