本文实例讲述了Python下实现的RSA加密/解密及签名/验证功能。分享给大家供大家参考,具体如下:
原文是py2环境,而我的环境是py3,所以对原代码做了修改:decode(), encode()
import rsa
# 生成密钥
(pubkey, privkey) = rsa.newkeys(1024)
# 保存密钥
with open('public.pem','w+') as f:
f.write(pubkey.save_pkcs1().decode())
with open('private.pem','w+') as f:
f.write(privkey.save_pk
1