小编dav*_*dad的帖子

用python中的AES生产ECB企鹅

我想加密图像中的数据,但生成的密文仍然是有效的图像.我在python中使用AES加密图像然后,我替换文件中的标头,但是窗口无法打开加密图像.

def encrypt_file(self, in_filename, out_filename):
    filesize = os.path.getsize(in_filename)
    iv = Random.new().read(AES.block_size)
    cipher = AES.new(self.key, AES.MODE_ECB, iv)
    chunksize = 64 * 1024
    with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:
            outfile.write(struct.pack('<Q', filesize))
            outfile.write(iv)

            while True:
                chunk = infile.read(chunksize)
                if len(chunk) == 0:
                    break
                elif len(chunk) % 16 != 0:
                    chunk += ' ' * (16 - len(chunk) % 16)
                cifrado = base64.b64encode(cipher.encrypt(chunk))
                print cifrado
                outfile.write(cipher.encrypt(chunk))
Run Code Online (Sandbox Code Playgroud)

我想要这个效果: 欧洲央行企鹅

python encryption image aes ecb

2
推荐指数
1
解决办法
2816
查看次数

标签 统计

aes ×1

ecb ×1

encryption ×1

image ×1

python ×1