【发布时间】:2010-06-17 19:14:40
【问题描述】:
我的团队,
我在 C# 中有以下加密代码。我收到了Specified initialization vector (IV) does not match the block size for this algorithm. 的例外情况@
你能告诉我这里缺少的链接是什么吗?
//Key and IV for RSA Encryption
byte[] ketByte = Encoding.UTF8.GetBytes("C3CA193570B26E5C3CBB50FD805A01S2");
byte[] IVByte = Encoding.UTF8.GetBytes("C3FG563570FG565C3CBB50FD805A01S2");
//Read image
Image sourceImg = Image.FromFile(@"D:\ImageSource\Cha1.bmp");
//Convert to Byte[]
byte[] byteArray = ImageToByteArray(sourceImg);
//Encrypt
byte[] encryptedByteArray = EncryptByte(byteArray, ketByte, IVByte);
public static byte[] EncryptByte(byte[] palinData, byte[] Key, byte[] theInitializationVector)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Security.Cryptography.Rijndael algorithm = System.Security.Cryptography.Rijndael.Create();
algorithm.Key = Key;
algorithm.IV = theInitializationVector; //Exception
System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(ms,algorithm.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
cStream.Write(palinData, 0, palinData.Length);
cStream.Close();
byte[] encryptedData = ms.ToArray();
return encryptedData;
}
谢谢
李乔
【问题讨论】:
标签: c# .net encryption