python自动生成公私钥
作者:互联网
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()
标签:generator,exportKey,公私,python,生成,decode,key,close 来源: https://blog.csdn.net/sleepIII/article/details/115393267