我发现了一些代码,我想把它们合并到我的Python加密程序中。它应该加密代码同一目录中的文件,我希望它以一个目录为目标。但是,它是用Python 2编写的,当我修改一些代码以适应Python 3时,我得到了以下错误:Traceback (most recent call last):
File "/home/pi/Desktop/Projects/FyleCript/Dev Files/encryption.py", line 77, in
encrypt(SHA256.new(password).digest(), str(Tfiles))
File "/usr/lib/python3/dist-packages/Crypto/Hash/SHA256.py", line 88, in new
return SHA256Hash().new(data)
File "/usr/lib/python3/dist-packages/Crypto/Hash/SHA256.py", line 75, in new
return SHA256Hash(data)
File "/usr/lib/python3/dist-packages/Crypto/Hash/SHA256.py", line 72, in __init__
HashAlgo.__init__(self, hashFactory, data)
File "/usr/lib/python3/dist-packages/Crypto/Hash/hashalgo.py", line 51, in __init__
self.update(data)
File "/usr/lib/python3/dist-packages/Crypto/Hash/hashalgo.py", line 69, in update
return self._hash.update(data)
TypeError: Unicode-objects must be encoded before hashing
但是代码在python2中运行得很好。我试着在某某和谷歌上寻找类似的问题,但没有帮助。在
代码:
^{pr2}$
有人能帮我解决这个问题吗?我使用了python2到3工具,但它仍然不起作用。在
另外,你能解决目录问题吗?没必要,但我很喜欢。在
编辑:我已经将str替换为bytes和{},但它返回相同的错误。在