【发布时间】:2018-05-02 13:01:22
【问题描述】:
我正在尝试恢复使用旧的纯 python 实现的河豚加密的文件。
旧代码依赖于单个 blofish.py 文件(版权所有 (C) 2002 Michael Gilfix)
旧数据被加密执行以下操作:
cipher = Blowfish(self.masterKey)
cipher.initCTR()
cleanData = cipher.decryptCTR(encData)
该代码未初始化现代河豚实现所需的随机数,因此我无法将其移植到 pycryptodome 函数
cipher = Blowfish.new(self.masterKey, Blowfish.MODE_CTR, nonce = ?????)
cleanData = cipher.decrypt(encData)
我能找到的唯一建议是在 initCTR 函数中,其中 iv 设置为 0(即使 CTR 模式没有 IV)
def initCTR(self, iv=0):
"""Initializes CTR mode of the cypher"""
assert struct.calcsize("Q") == self.blocksize()
self.ctr_iv = iv
self._calcCTRBUF()
def _calcCTRBUF(self):
"""Calculates one block of CTR keystream"""
self.ctr_cks = self.encrypt(struct.pack("Q", self.ctr_iv)) # keystream block
self.ctr_iv += 1
self.ctr_pos = 0
有人可以帮我吗?
【问题讨论】:
标签: python-2.7 pycrypto blowfish pycryptodome