DES密码与pyca/密码学(PBEWithMD5和DES)

2024-10-02 04:24:11 发布

您现在位置:Python中文网/ 问答频道 /正文

为了支持一些遗留应用程序,我需要在python中实现PBEWithMD5AndDESRFC2898 Section 6.1)。我知道这是不安全的,弃用,不应该再使用。但遗憾的是,这是我的要求。在

我已经有了一个使用PyCrypto/PyCryptodome的工作版本,但是我需要引入{a2}作为项目的附加依赖,这是我想要避免的。因为我们已经在代码的其他部分使用了^{},所以我更喜欢这个库而不是{}。但是由于PBEWithMD5AndDES的性质,我需要DES加密支持,但是据我所知,pyca/cryptography只支持三重DES(3DES)。在

有没有一种方法可以使用pyca/cryptography对某些内容进行(单)DES加密?{{cd5>的用法基本上需要用cd5}来代替:

key, init_vector = _pbkdf1_md5(a_password, a_salt, a_iterations)
cipher = DES.new(key, DES.MODE_CBC, init_vector)
encrypted_message = cipher.encrypt(encoded_message)



更新

多亏了@SquareRootOfTwentyThree,我最终得出了这样的结论:

^{pr2}$

Tags: key应用程序messageinitsectioncryptographyciphervector
1条回答
网友
1楼 · 发布于 2024-10-02 04:24:11

Is there a way to (single) DES encrypt something using pyca/cryptography?

是的,只需将一个8字节的密钥传递给cryptography.hazmat.primitives.ciphers.algorithms.TripleDES。这将对三重DES中的每个DES变换使用相同的键。在

三重DES也称为DES-EDE,用于加密、解密和加密。如果对每一个都使用相同的密钥,则其中一个加密/解密对将产生identity函数,只留下一个DES encrypt。在


请注意,并非所有的三重DES实现都会接受一个密钥(因为通常存在单个DES),但这一个可以:

The secret key. This must be kept secret. Either 64, 128, or 192 bits long. DES only uses 56, 112, or 168 bits of the key as there is a parity byte in each component of the key. Some writing refers to there being up to three separate keys that are each 56 bits long, they can simply be concatenated to produce the full key.

尽管我必须承认,你必须理解tripledes是如何工作的,才能理解这篇文章。在

另外请注意,对于单个DES的DES-EDE的实现目前尚未优化,即使其中两个操作相互抵消,它仍将执行所有三个操作。在

相关问题 更多 >

    热门问题