You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
758 B

import os
from Crypto.PublicKey import RSA
def A_key():
# 生成密钥对
key = RSA.generate(2048)
# 获取私钥和公钥
private_key = key.export_key()
public_key = key.publickey().export_key()
# 获取当前文件的目录路径
current_directory = os.path.dirname(__file__)
# 保存私钥到文件(相对路径)
private_file_path = os.path.join(current_directory, 'A_private.txt')
with open(private_file_path, 'wb') as private_file:
private_file.write(private_key)
# 保存公钥到文件(相对路径)
public_file_path = os.path.join(current_directory, 'A_public.txt')
with open(public_file_path, 'wb') as public_file:
public_file.write(public_key)