From 6fe5b455e2b6e7512fdcdbc42ace3a51407a218c Mon Sep 17 00:00:00 2001 From: pyj256ost <2940908360@qq.com> Date: Wed, 13 Dec 2023 19:55:06 +0800 Subject: [PATCH] ADD file via upload --- A_private_public.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 A_private_public.py diff --git a/A_private_public.py b/A_private_public.py new file mode 100644 index 0000000..f606c23 --- /dev/null +++ b/A_private_public.py @@ -0,0 +1,23 @@ +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)