Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TripleDES IV for C#?

So when I say something like:

TripleDES tripledes = TripleDES.Create();
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(password, plain);
tripledes.Key = pdb.GetBytes(16);
tripledes.IV = pdb.GetBytes(16);

I get an error. The error used to be on the key, but its been fixed (I think - unless you spot something wrong). However, the error occurs when I set the IV:

tripledes.IV = pdb.GetBytes(16);

It says that its not a valid initialization vector.

How do I fix it?

like image 305
Alper Avatar asked Feb 24 '23 21:02

Alper


1 Answers

The block size for TripleDES is 64 bits. You are trying to set 128 bits.

This should work:

tripledes.IV = pdb.GetBytes(8);
like image 131
Gonzalo Avatar answered Mar 07 '23 23:03

Gonzalo