小编use*_*421的帖子

在Python 3中使用AES和PyCrypto加密文件

我正在使用PyCrypto在CBC模式下使用AES加密二进制文件(Python 3.2.3 64位和PyCrypto 2.6).使用以下代码:http://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/

但遇到以下错误:ValueError:IV必须长度为16个字节.

这是代码:

def encryptFile(key, in_filename, out_filename=None, chunksize=64*1024):
""" Encrypts a file using AES (CBC mode) with the
    given key.

    key:
        The encryption key - a string that must be
        either 16, 24 or 32 bytes long. Longer keys
        are more secure.

    in_file:
        Input file

    out_file:
        If None, a StringIO will be returned.

    chunksize:
        Sets the size of the chunk which the function
        uses to read and encrypt the file. Larger chunk
        sizes can …
Run Code Online (Sandbox Code Playgroud)

python pycrypto python-3.x

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

pycrypto ×1

python ×1

python-3.x ×1