perf: 优化超长文本rsa加密解密 (#312)
This commit is contained in:
parent
c4c4934932
commit
a788d8f3b8
@ -62,18 +62,6 @@ def get_key_pair_by_sql():
|
|||||||
return system_setting.meta
|
return system_setting.meta
|
||||||
|
|
||||||
|
|
||||||
# def get_key_pair():
|
|
||||||
# if not os.path.exists("/opt/maxkb/conf/receiver.pem"):
|
|
||||||
# kv = generate()
|
|
||||||
# private_file_out = open("/opt/maxkb/conf/private.pem", "wb")
|
|
||||||
# private_file_out.write(kv.get('value'))
|
|
||||||
# private_file_out.close()
|
|
||||||
# receiver_file_out = open("/opt/maxkb/conf/receiver.pem", "wb")
|
|
||||||
# receiver_file_out.write(kv.get('key'))
|
|
||||||
# receiver_file_out.close()
|
|
||||||
# return {'key': open("/opt/maxkb/conf/receiver.pem").read(), 'value': open("/opt/maxkb/conf/private.pem").read()}
|
|
||||||
|
|
||||||
|
|
||||||
def encrypt(msg, public_key: str | None = None):
|
def encrypt(msg, public_key: str | None = None):
|
||||||
"""
|
"""
|
||||||
加密
|
加密
|
||||||
@ -111,7 +99,6 @@ def rsa_long_encrypt(message, public_key: str | None = None, length=200):
|
|||||||
:param length: 1024bit的证书用100, 2048bit的证书用 200
|
:param length: 1024bit的证书用100, 2048bit的证书用 200
|
||||||
:return: 加密后的数据
|
:return: 加密后的数据
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 读取公钥
|
# 读取公钥
|
||||||
if public_key is None:
|
if public_key is None:
|
||||||
public_key = get_key_pair().get('key')
|
public_key = get_key_pair().get('key')
|
||||||
@ -143,7 +130,6 @@ def rsa_long_decrypt(message, pri_key: str | None = None, length=256):
|
|||||||
:param length : 1024bit的证书用128,2048bit证书用256位
|
:param length : 1024bit的证书用128,2048bit证书用256位
|
||||||
:return: 解密后的数据
|
:return: 解密后的数据
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if pri_key is None:
|
if pri_key is None:
|
||||||
pri_key = get_key_pair().get('value')
|
pri_key = get_key_pair().get('value')
|
||||||
cipher = PKCS1_cipher.new(RSA.importKey(pri_key, passphrase=secret_code))
|
cipher = PKCS1_cipher.new(RSA.importKey(pri_key, passphrase=secret_code))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user