当我试图加密/与蟒蛇pycrypto解密加密失去字符串的一部分。大部分事情都顺利工作,但我得到一个奇怪的问题,当解密data.I试图加密/解密的一些JPG文件进行测试,虽然它们加密/没有问题解密,解密后的文件无法/损坏打开。试图找到我保存的文本文件里有类似的随机一句“测试此文件的完整性等等等等等等”的问题,它只有在“诚信....等等等等等等”正确解密,完整性之前一切都还是乱码字符。我不是AES该见地,但即时假设这是一个编码/解码或填充错误。pycrypto加密/解密,解密
这里是我的代码:
#encryption
iv = Random.new().read(AES.block_size)
filePath = input("Path to file for encryption: ")
selFile = open(filePath, 'rb')
getBytes = bytes(selFile.read())
encPW = input("Enter password: ")
hashpw = hashlib.sha256(encPW.encode('UTF-8').digest())
destination = input("Destination path for encrypted file: ")
aes = AES.new(hashpw, AES.Mode_CFB, iv)
encFile = base65.b64encode(aes.encrypt(getBytes))
writetofile = open(destination, 'wb')
writetofile.write(encFile)
writetofile.close()
print("Encryption successful")
#Decryption
iv = Random.new().read(AES.block_size)
filePath = input("Path to file for decryption: ")
selFile = open(filePath, 'rb')
getBytes = bytes(selFile.read())
decPW = input("Enter password: ")
hashdecpw = hashlib.sha256(encPW.encode('UTF-8').digest())
destination = input("Destination path for decrypted file: ")
aes = AES.new(hashdecpw, AES.Mode_CFB, iv)
decFile = aes.decrypt(getBytes)
writetofile = open(destination, 'wb')
writetofile.write(decFile)
writetofile.close()
print("Decryption successful")
上什么可能会造成的第一个字符的损失,并阻止我的加密/解密正确的文件任何想法?
请不要恶意破坏你的帖子。 – DJMcMayhem
请不要破坏你的帖子。一旦你发布了一个问题,你已经将内容授权给了Stack Overflow社区(在CC-by-SA许可下)。如果您想取消关联此帐户与您的帐户关联,请参阅[解除请求的正确途径是什么?](http://meta.stackoverflow.com/questions/323395/what-is-the-proper-route-换一个 - 解离 - 请求)。 – Bugs