Alper
Alper

Reputation: 1

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?

Upvotes: 5

Views: 8269

Answers (1)

Gonzalo
Gonzalo

Reputation: 21175

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

This should work:

tripledes.IV = pdb.GetBytes(8);

Upvotes: 8

Related Questions