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.
|
|
|
import base64
|
|
|
|
import os
|
|
|
|
|
|
|
|
from config import config
|
|
|
|
from tool.asymmetric import RSA
|
|
|
|
|
|
|
|
|
|
|
|
def getUserKey() -> (str, str): # 返回base64编码
|
|
|
|
# 检查是否存在公私钥文件
|
|
|
|
if not os.path.exists(config.priKeySavePath) or not os.path.exists(config.pubKeySavePath):
|
|
|
|
# 生成新的密钥对
|
|
|
|
RSA.generate_keys(config.priKeySavePath,config.pubKeySavePath)
|
|
|
|
# 读取私钥
|
|
|
|
with open(config.priKeySavePath, "rb") as f:
|
|
|
|
data = f.read()
|
|
|
|
private_key = base64.b64encode(data).decode('utf-8')
|
|
|
|
|
|
|
|
# 读取公钥
|
|
|
|
with open(config.pubKeySavePath, "rb") as f:
|
|
|
|
data = f.read()
|
|
|
|
public_key = base64.b64encode(data).decode('utf-8')
|
|
|
|
|
|
|
|
return private_key, public_key
|