File size increases sharply after brine

I read in a file and send the data (once encrypted) to the dictionary, with a data hash before and after encryption. Then I select the dictionary, but I think the file size is massive compared to the size of the original file. If I write encrypted data directly to a file, the size is identical to the original. Any idea why my pickle file is so big?

#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()
+3
source share
1 answer

Try using a binary pickle with protocol=2pickle.dump as an argument. This should be much more efficient.

+6
source

Source: https://habr.com/ru/post/1721778/


All Articles