pycryptodome模块安装:
pip install pycryptodome==3.10.1
实例:通过python自动生成公私钥
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
from Crypto import Random
from Crypto.PublicKey import RSA
random_generator = Random.new().read
key = RSA.generate(2048, random_generator)
# 生成私钥
f = open('private.rsa', 'w')
f.write(key.exportKey().decode('utf-8'))
f.close()
# 生成公钥
f = open('public.rsa', 'w')
f.write(key.publickey().exportKey().decode('utf-8'))
f.close()