Triple DES加密需要多少个密钥? [英] How many keys does Triple DES encryption need?

查看:293
本文介绍了Triple DES加密需要多少个密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些C#代码移植到C ++,并尝试使用三重DES加密来加密文本文件。但我很困惑一些加密API只需要三重DES的一个密钥(C#,例如:如何在C#(完整示例)中实现Triple DES),而其他需要2或3个键(在我发现的几个C ++实现中)。



为什么?

解决方案

TDEA 键入在这里可以更好地理解,考虑到一个简单的键的关键长度。根据所使用的键控选项,它可以是单键长度,双键长度或三键长度。所有部分都是必需的,将构成密钥包。



TDEA基本上是DES密码的三个应用程序。 密钥包的每个部分都与DES密码算法的一个或多个执行一起使用(另见 Feistel密码);




  • 单个键,使用三次(相当于经典DES,但不再推荐) ,K1 = K2 = K3;

  • 双键,键的第一部分使用两次,K1和K2是独立的,K3 = K1;

  • ,对于三键长度,每个关键部分都使用一次,所有部分都是独立的。



你看到了什么作为两个(或三)键最有可能使用双重(或三重)密钥长度,每个部分都是单独提供的。



API应该提供关于如何提供/预期的详细信息。



一些用于检查互操作性的测试用例从不受伤。






有关TDEA工作原理的一些背景/背景;来源维基百科;


三重DES使用包括三个DES密钥K1,K2和K3的密钥束,每个56位(不包括奇偶校验位)...



加密算法是:



密文= E (D< K1< sub>(plaintext)))



即,DES使用K1进行加密,使用K2解密DES,然后用K3 DES加密。



解密是相反的:



明文= D (E K2 (D K3 (ciphertext)))



也就是用K3解密,用K2加密,然后用K1解密



每个三重加密加密一个64位数据块。



I am porting some C# code to C++, and trying to encrypt a textfile with Triple DES encryption. But I am confused; some encryption APIs only require one key for Triple DES (C# for example: How to implement Triple DES in C# (complete example) ), while others require 2 or 3 keys (in several C++ implementations I've found).

Why is that?

解决方案

The TDEA keying is maybe better understood here considering the key length over just a simple key. Depending on the keying option used, it can be a single key length, double key length, or triple key length. All parts are required and would constitute the "key bundle".

The TDEA is basically three applications of the DES cipher. Each part of the "key bundle" is used with one or more executions of the DES cipher algorithm (see also the Feistel cipher);

  • for a single key, it is used three times (equates to classic DES but is no longer recommended), K1 = K2 = K3;
  • for a double key, the first part of the key is used twice, K1 and K2 are independent and K3 = K1;
  • and for the triple key length, each key part is used once, all parts are independent.

What you are seeing as "two" (or "three") keys is most likely the double (or triple) key length being used, each part being provided separately.

The documentation for each API should provide details on how the keys are provided/expected.

A few test cases to check interoperability never hurt either.


Some background/context on how TDEA works; source Wikipedia;

Triple DES uses a "key bundle" that comprises three DES keys, K1, K2 and K3, each of 56 bits (excluding parity bits)...

The encryption algorithm is:

ciphertext = EK3(DK2(EK1(plaintext)))

I.e., DES encrypt with K1, DES decrypt with K2, then DES encrypt with K3.

Decryption is the reverse:

plaintext = DK1(EK2(DK3(ciphertext)))

I.e., decrypt with K3, encrypt with K2, then decrypt with K1.

Each triple encryption encrypts one block of 64 bits of data.

这篇关于Triple DES加密需要多少个密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆