fix(authentication): 修复登录时有时解密失败

This commit is contained in:
ibuler
2020-08-19 21:22:28 +08:00
committed by BaiJiangJie
parent 9ca8ab218c
commit 0fd2f18240
2 changed files with 8 additions and 1 deletions

View File

@@ -34,7 +34,13 @@ def rsa_decrypt(cipher_text, rsa_private_key=None):
if rsa_private_key is None:
# rsa_private_key 为 None可以能是API请求认证不需要解密
return cipher_text
key = RSA.importKey(rsa_private_key)
cipher = PKCS1_v1_5.new(key)
message = cipher.decrypt(base64.b64decode(cipher_text.encode()), 'error').decode()
cipher_decoded = base64.b64decode(cipher_text.encode())
# Todo: 弄明白为何要以下这么写https://xbuba.com/questions/57035263
if len(cipher_decoded) == 127:
hex_fixed = '00' + cipher_decoded.hex()
cipher_decoded = base64.b16decode(hex_fixed.upper())
message = cipher.decrypt(cipher_decoded, b'error').decode()
return message