我正在读取文件并将数据(一旦加密)发送到字典,并在加密之前和之后对数据进行哈希处理。然后我腌制字典,但发现文件大小与源文件大小相比很大。如果我将加密数据直接写入文件,则大小与源相同。知道为什么我的腌制文件这么大吗?
#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()