为了支持一些遗留应用程序,我需要在python中实现PBEWithMD5AndDES
(RFC2898 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,我最终得出了这样的结论:
是的,只需将一个8字节的密钥传递给
cryptography.hazmat.primitives.ciphers.algorithms.TripleDES
。这将对三重DES中的每个DES变换使用相同的键。在三重DES也称为DES-EDE,用于加密、解密和加密。如果对每一个都使用相同的密钥,则其中一个加密/解密对将产生identity函数,只留下一个DES encrypt。在
请注意,并非所有的三重DES实现都会接受一个密钥(因为通常存在单个DES),但这一个可以:
尽管我必须承认,你必须理解tripledes是如何工作的,才能理解这篇文章。在
另外请注意,对于单个DES的DES-EDE的实现目前尚未优化,即使其中两个操作相互抵消,它仍将执行所有三个操作。在
相关问题 更多 >
编程相关推荐