i Team,
I have the following encryption code in C#. I am getting an exception as Specified initialization vector (IV) does not match the block size for this algorithm.
Could you please tell me what is the missing link here?
//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;
}
Thanks
Lijo