DES加密的问题
下面的加密函数,输入正确的参数(包括不超过10位的源串),返回的加密串是空值,不知道哪里出了问题,请各位高手帮忙看看:
String^ EnCrypt(String^ srcString,array<unsigned char>^ DESKey,array<unsigned char>^ DESIv)
{
DESCryptoServiceProvider^ DESalg = gcnew DESCryptoServiceProvider;
DESalg->KeySize = 64;
DESalg->Key = DESKey;
DESalg->IV = DESIv;
System::IO::MemoryStream^ mStream = gcnew System::IO::MemoryStream(100);
System::Text::ASCIIEncoding^ ascEncoding = gcnew System::Text::ASCIIEncoding;
array<unsigned char>^ chrArray = ascEncoding->GetBytes(srcString);
CryptoStream^ crpStream = gcnew CryptoStream(mStream,DESalg->CreateEncryptor(),CryptoStreamMode::Write);
crpStream->Write(chrArray,0,chrArray->Length);
crpStream->Flush();
return ascEncoding->GetString(mStream->ToArray());
}
[解决办法]