import base64 import boto3 from fansifter_common.utils.functional import lazy_proxy from app.config import settings _client = lazy_proxy( lambda: boto3.client( "kms", region_name=settings.aws_region_name, ), ) def decrypt(ciphertext: str) -> str: response = _client.decrypt( CiphertextBlob=base64.b64decode(ciphertext), KeyId=settings.kms_key_arn, EncryptionContext={"field": "token"}, ) return response["Plaintext"].decode()