检索加密数据的实际大小
在.NET框架中,我试图加密一些二进制数据(使用RijndaelManaged),为了解密,我使用了以下示例代码(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);
现在,decryptedData除了空值之外还包含有用的数据(作为数组初始化) ,我怎样才能获得加密数据的实际大小(如果它是字符串,我可以停在第一个空值!)。
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 get the actual size of encrypted data ( if it was string I can just stop at the first null!).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要单独存储长度,或者作为加密数据的前 N 位/字节,或者在加密数据之外。
Rijndael 是一种分组密码,这意味着它始终会加密整个块,并且解密时您总是会得到整个块。
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.