In .NET framework, I'm trying to encrypt some binary data (using RijndaelManaged), for decrypting I used the following sample code (C++/.NET):
RijndaelManaged^ rjdAlg= gcnew RijndaelManaged;
rjdAlg->IV= IV;
rjdAlg->Key=this->key;
ICryptoTransform^ decryptor= rjdAlg->CreateDecryptor();
MemoryStream^ msDecrypt = gcnew MemoryStream(encryptedData);
CryptoStream^ csDecrypt = gcnewCryptoStream(msDecrypt,decryptor,CryptoStreamMode::Read);
array<unsigned char>^ decryptedData= gcnew array<unsigned char>(encryptedData->Length);
csDecrypt->Read(decryptedData,0,decryptedData->Length);
Now, decryptedData contains useful data in addition to nulls (as the array initialization), how can I开发者_如何学C get the actual size of encrypted data ( if it was string I can just stop at the first null!).
You need to store the length separately, either as the first N bits/bytes of your encrypted data, or outside of the encrypted data.
Rijndael is a block cipher, which means it will always encrypt whole blocks, and you always get whole blocks back when decrypting.
精彩评论