开发者

retrieving encrypted data actual size

开发者 https://www.devze.com 2023-03-03 22:11 出处:网络
In .NET framework, I\'m trying to encrypt some binary data (using RijndaelManaged), for decrypting I used the following sample code (C++/.NET):

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号