RSA

RSA保存格式有两种

python的rsa库是真的垃圾

  • 读取privatekey可以带rsa标识,public不行
  • 不带rsa时,public可以,private不行

使用pycrypto

from Crypto.PublicKey import RSA

with open('private.pem', 'rb') as f:
privateFile = f.read()
privateKey = RSA.importKey(privateFile)

with open('public.pem', 'rb') as pf:
publicFile = pf.read()
publicKey = RSA.importKey(publicFile)

print(privateKey)
print(publicKey)

参考

https://www.shangyang.me/2017/05/24/encrypt-rsa-keyformat/
https://www.jianshu.com/p/f7926b66cfc0