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