3
我正在讀文件並將數據(一旦加密後)發送到字典中,並在加密前後使用數據散列。然後我醃製字典,但發現文件大小與源文件大小相比是巨大的。如果我將加密數據直接寫入文件,則其大小與源相同。任何想法爲什麼我的醃製文件是如此之大?醃菜後文件大小顯着增加
#Encrypt data and get hashes
def encryptAndExportFile(self, key, inFile, outFile):
openInFile = open(inFile,"rb")
inFileSize = os.path.getsize(inFile)
inFileData = openInFile.readlines()
openInFile.close()
""" initialise cipher """
cipher = AES.new(key, AES.MODE_CFB)
""" initialise MD5 """
m = hashlib.md5() #hash
h = hashlib.md5() #hash of encrypted dataq
encryptedData = []
for data in inFileData:
m.update(data)
encData = cipher.encrypt(data)
h.update(encData)
encryptedData.append(encData)
hashResult = m.digest()
encHashResult = h.digest()
return hashResult, encryptedData, encHashResult
def storeEncryptedObject(self, obj, path):
outFile = open(path, 'wb')
pickle.dump(obj, outFile)
outFile.close()
工作過!謝謝! – zyrus001 2009-11-03 13:07:21