I use crypto++ to encrypt text with AES and save to File,then read file decrypt the text,but the text decrypt not exactly the same with the original text? I don't know why?
exapme:
original text:/*+++++++lskjdflksdfj
decrypt text: /*++1++++lskjdflksdfj
only one byte not the same!
The code is Here, I'am sure the key and iv is the same;
Encrypt code:
std::string strCiphertext = "";
AES::Encryption aesEncryption(mKey, mKeyLen);
string cipher;
CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, mIv);
StreamTransformationFilter stfEncryptor(cbcEncryption, new HexEncoder(new StringSink(cipher)));
stfEncryptor.Put((byte*)(plainText.c_str()), plainText.length());
stfEncryptor.MessageEnd();
Decrypt code:
string encoded;
StringSource s(cryptText, true, new HexDecoder(new StringSink(encoded)));
Log::log("before ...");
std::string strDecryptedText = "";
try
{
AESDecryption aesDecryption(mKey, mKeyLen);
CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, mIv);
StreamTransformationFilter stfDecryptor(cbcDecryption, new StringSink(strDecryptedText));
stfDecryptor.Put(reinterpret_cast<const unsigned="" char="">(encoded.c_str()), encoded.length());
stfDecryptor.MessageEnd();
Log::log(strDecryptedText);
}
catch (const std::exception& ex)
{
Log::log(ex.what());
}
Log::log("after ...");
Any one can help me,thanks a lot!