當我試圖加密/與蟒蛇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