简体   繁体   中英

TripleDESCryptoServiceProvider Specified key is not a valid size for this algorithm at 128 bytes?

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?

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.

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