简体   繁体   中英

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?

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

This should work:

tripledes.IV = pdb.GetBytes(8);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM