Trouble with initialization vector (IV) for AES

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hi

asp.net 3.5

This code below gives this error:
Specified initialization vector (IV) does not match the block size for this
algorithm.

byte[] initVectorBytes = Encoding.ASCII.GetBytes("1234567890");
byte[] secretkey =
Encoding.ASCII.GetBytes("12345678901234567890123456789012");
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
symmetricKey.BlockSize = 128;
symmetricKey.KeySize = 256;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(secretkey,
initVectorBytes);

I wonder how many bytes the initialization vector should have. I've tried 32
bytes (the same as the key, without any luck)
any suggestions?
 
This code below gives this error:
Specified initialization vector (IV) does not match the block size for this
algorithm.

byte[] initVectorBytes = Encoding.ASCII.GetBytes("1234567890");
byte[] secretkey =
Encoding.ASCII.GetBytes("12345678901234567890123456789012");
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
symmetricKey.BlockSize = 128;
symmetricKey.KeySize = 256;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(secretkey,
initVectorBytes);

I wonder how many bytes the initialization vector should have. I've tried 32
bytes (the same as the key, without any luck)
any suggestions?

IV should be 16 bytes, because it has to be the same as block size.

Arne
 
Back
Top