From: Jeff on
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?



From: Arne Vajhøj on
On 21-06-2010 15:40, Jeff wrote:
> 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

From: rossum on
On Mon, 21 Jun 2010 21:40:52 +0200, "Jeff"
<it_consultant1(a)hotmail.com.NOSPAM> wrote:

>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?
Read the error message. It tells you how many bytes the IV should
have: "does not match the block size". Look up the block size for AES
and you will know that you need 128 bits of IV because AES has a 128
bit block size.

There is a lot of helpful information in error messages; it is always
worthwhile reading them.

rossum