首页 > 解决方案 > 在 python 中使用 zipfile 加密和解密 RSA 密码术

问题描述

我想用 RSA 加密或任何其他公钥/私钥加密算法加密压缩的 zipfile。我可以轻松地加密文件,但我无法使用 zipfile 执行此操作。任何人都可以知道所以请帮助我。

pr_key = RSA.import_key(open('private_pem.pem', 'r').read())
pu_key = RSA.import_key(open('public_pem.pem', 'r').read())
# print(type(pr_key), type(pu_key))#Instantiating PKCS1_OAEP object with the public key for encryption
cipher = PKCS1_OAEP.new(key=pu_key)

#Encrypting the message with the PKCS1_OAEP object
# fd = open('1.zip', 'rb')
# # fd.write(b'Hello World')
# fd.close()

fd = open('1.zip', 'rb')
unencrypted_blob = fd.read()
fd.close()
cipher_text = cipher.encrypt(unencrypted_blob)
fd = open('encry.zip', 'wb')
fd.write(cipher_text)
fd.close()

标签: pythoncryptographyrsapublic-key-encryptionzipfile

解决方案


推荐阅读