python - 在 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()
解决方案
推荐阅读
- java - Java 中的 desktop.open 打开 .bat 文件而不是文件夹
- python - Pip EnvironmentError - 无法升级包
- scala - 如何在 Scala 中接受多种类型
- assembly - 如何检索两个大数的总和?
- ios - Firebase Crashlytics:缺少可选的 dSYM
- spring-boot - 具有正确行数但具有空字段的 Spring JPA 结果查询
- php - 如何循环不同的csv并合并它们?
- css - CSS - 带有右边框细化的打字机动画
- mysql - Mysql 巨大的表,count(*) 的问题很慢
- django - Django prefetch_related 需要大量运行时间