2

I'm trying to update my encrypt decrypt function from DES to TripleDES. However, when I try to increase my key and iv byte array size from 8 to 128:

byte[] key = new byte[128], iv = new byte[128];
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();

Where 8 was used for DESCryptoServiceProvider and 128 is now used for TripleDESCryptoServiceProvider I always get the same error:

Specified key is not a valid size for this algorithm.

Even though my byte arrays are complete filled in.

What am I doing wrong? Is there any requirement besides the length to allow my key and iv to be used to create an Encryptor?

reaper_unique
  • 2,916
  • 3
  • 28
  • 48

1 Answers1

7

Key sizes are in bits not in bytes. 3DES key size is 168, 112 or 56 bits, depending on keying option. The C# implementation supports key sizes of 128 and 192 bits, from which it will only use 112 and 168 bits, respectively.

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569