生成代码:
import rsa
public_key,private_key = rsa.newkeys(2048)
#生成公钥
public_key_bytes = public_key.save_pkcs1()
with open('public.pem','wb')as f:
f.write(public_key_bytes)
#生成私钥
private_key_bytes = private_key.save_pkcs1()
with open('private.pem','wb')as f:
f.write(private_key_bytes)
生成的公钥:
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAh151YMf/6iW6wXHa8BJs5DPPX20azt3hCzZvI85/G/aoNhbY1AAp
AV3OfcpYZewxgdhxaZ8lMQ/ien1m7Qv9xI/9f0iTWkIhW2euG8QmkDMpOfqYHfD+
7ZX3fnvLk8kxTZJ14QIlQMeTISwukTw6z4ZFXuYXMY6jF4LKS0EozQeC4aYP3nU4
fqYdbXcxJet54B5VKJ8Fr9vlh8jqhj8hSHnhgXrpCLyHN1FkFMbcPrI9+KHJCJiE
P/h9ZebpoK5zYfZ0v6CtEWLUtczLaR3La8PKaIafhVwJJK8VGzzB5DrSsws+U9xP
a3aZyfQBUqLA484N0lDJz7DGTjs3e94HewIDAQAB
-----END RSA PUBLIC KEY-----
生成的私钥:
-----BEGIN RSA PRIVATE KEY