更新了py的客户端

This commit is contained in:
Alex
2025-08-01 23:00:40 +08:00
parent 7e4722c9e5
commit 0044638a40
10 changed files with 466 additions and 1 deletions
+43
View File
@@ -0,0 +1,43 @@
# scripts/gen_keys.py
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
import os
KEY_DIR = os.path.join(os.path.dirname(__file__), '../config/keys')
PRIVATE_KEY_PATH = os.path.join(KEY_DIR, 'private_key.pem')
PUBLIC_KEY_PATH = os.path.join(KEY_DIR, 'public_key.pem')
def generate_keys():
# 确保目录存在
os.makedirs(KEY_DIR, exist_ok=True)
# 生成私钥
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
priv_bytes = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption()
)
# 生成公钥
public_key = private_key.public_key()
pub_bytes = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
# 写入文件
with open(PRIVATE_KEY_PATH, 'wb') as f:
f.write(priv_bytes)
with open(PUBLIC_KEY_PATH, 'wb') as f:
f.write(pub_bytes)
print(f"[√] 私钥已保存到 {PRIVATE_KEY_PATH}")
print(f"[√] 公钥已保存到 {PUBLIC_KEY_PATH}")
if __name__ == '__main__':
generate_keys()