pythonrsa-oaep如何实现加密-创新互联
python rsa-oaep如何实现加密?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

代码:
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
import base64
rsa_key_pair = RSA.generate(1024)
pubkey = rsa_key_pair.publickey().export_key()
privkey = rsa_key_pair.export_key()
print(pubkey.decode())
print(privkey.decode())
# 公钥加密
text = "hello world"
rsa_pubkey = RSA.import_key(pubkey)
cipher_pub = PKCS1_OAEP.new(rsa_pubkey)
ciphervalue_enc = base64.b64encode(cipher_pub.encrypt(text.encode("utf-8")))
print("加密内容:\n{}".format(ciphervalue_enc.decode()))
#私钥解密
rsa_privkey = RSA.import_key(privkey)
cipher_priv = PKCS1_OAEP.new(rsa_privkey)
ciphervalue_dec = cipher_priv.decrypt(base64.b64decode(ciphervalue_enc))
print("解密内容:\n{}".format(ciphervalue_dec.decode())) 本文名称:pythonrsa-oaep如何实现加密-创新互联
网站网址:http://www.scyingshan.cn/article/dshsgj.html


咨询
建站咨询
