Trouble with initialization vector (IV) for AES

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?
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top