【问题标题】:file size is dramatically increased after pickle泡菜后文件大小显着增加
【发布时间】:2009-11-03 12:48:28
【问题描述】:

我正在读取一个文件并将数据(一旦加密)发送到字典,其中包含加密前后数据的哈希值。然后我腌制字典,但发现文件大小与源文件大小相比很大。如果我将加密数据直接写入文件,则大小与源相同。知道为什么我的腌制文件这么大吗?

#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()

【问题讨论】:

    标签: python encryption aes pickle


    【解决方案1】:

    通过将protocol=2 指定为pickle.dump 的关键字参数,尝试使用二进制pickle。它应该更有效率。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 2019-02-28
      相关资源
      最近更新 更多