fix: private.pem keyPath error in windows (#22814)

Co-authored-by: songkunling <songkunling@cabrtech.com>
This commit is contained in:
Song Kylin
2025-07-23 23:29:46 +08:00
committed by GitHub
parent 8c3e390172
commit 0731db8c22

View File

@@ -1,4 +1,5 @@
import hashlib
import os
from typing import Union
from Crypto.Cipher import AES
@@ -17,7 +18,7 @@ def generate_key_pair(tenant_id: str) -> str:
pem_private = private_key.export_key()
pem_public = public_key.export_key()
filepath = "privkeys/{tenant_id}".format(tenant_id=tenant_id) + "/private.pem"
filepath = os.path.join("privkeys", tenant_id, "private.pem")
storage.save(filepath, pem_private)
@@ -47,7 +48,7 @@ def encrypt(text: str, public_key: Union[str, bytes]) -> bytes:
def get_decrypt_decoding(tenant_id: str) -> tuple[RSA.RsaKey, object]:
filepath = "privkeys/{tenant_id}".format(tenant_id=tenant_id) + "/private.pem"
filepath = os.path.join("privkeys", tenant_id, "private.pem")
cache_key = "tenant_privkey:{hash}".format(hash=hashlib.sha3_256(filepath.encode()).hexdigest())
private_key = redis_client.get(cache_key)