【发布时间】:2013-08-28 19:06:54
【问题描述】:
我正在尝试使用 AES 128 CBC 加密字符串,并且我一直在关注 MSDN 示例: http://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
但是当我这样做时:
encKey = msEncrypt->ToArray();
调试时我的数组长度为零。为什么 encKey 数组没有填充加密输出? 实现代码:
ICryptoTransform^ encryptor = encAES->CreateEncryptor();
MemoryStream^ msEncrypt = gcnew MemoryStream();
CryptoStream^ csEncrypt = gcnew CryptoStream(msEncrypt, encryptor, CryptoStreamMode::Write);
StreamWriter^ swEncrypt = gcnew StreamWriter(csEncrypt);
swEncrypt->Write(publicKey);
encKey = msEncrypt->ToArray();
感谢您的帮助。
解决方案:
ICryptoTransform^ encryptor = encAES->CreateEncryptor();
MemoryStream^ msEncrypt = gcnew MemoryStream();
CryptoStream^ csEncrypt = gcnew CryptoStream(msEncrypt, encryptor, CryptoStreamMode::Write);
StreamWriter^ swEncrypt = gcnew StreamWriter(csEncrypt);
swEncrypt->Write(publicKey);
swEncrypt->Close();
csEncrypt->Close();
encKey = msEncrypt->ToArray();
msEncrypt->Close();
【问题讨论】:
标签: visual-studio-2010 visual-c++ encryption aes msdn