{"record":{"id":"47dea8f07b9f315a","repo":"BerriAI/litellm","slug":"master-key-must-be-32-bytes-for-aes-256-gcm","errorCode":null,"errorMessage":"Master key must be 32 bytes for AES-256-GCM","messagePattern":"Master key must be 32 bytes for AES-256-GCM","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/app_crypto.py","lineNumber":12,"sourceCode":"import base64\nimport json\nimport os\nfrom typing import Final\n\nfrom cryptography.hazmat.primitives.ciphers.aead import AESGCM\n\n\nclass AppCrypto:\n    def __init__(self, master_key: bytes):\n        if len(master_key) != 32:\n            raise ValueError(\"Master key must be 32 bytes for AES-256-GCM\")\n        self.key = master_key\n\n    def encrypt_json(self, data: dict, aad: bytes | None = None) -> dict:\n        aes: Final = AESGCM(self.key)\n        nonce: Final = os.urandom(12)\n        plaintext: Final = json.dumps(data).encode(\"utf-8\")\n        ct: Final = aes.encrypt(nonce, plaintext, aad)\n        ciphertext, tag = ct[:-16], ct[-16:]\n        return {\n            \"nonce\": base64.b64encode(nonce).decode(),\n            \"ciphertext\": base64.b64encode(ciphertext).decode(),\n            \"tag\": base64.b64encode(tag).decode(),\n        }\n\n    def decrypt_json(self, enc: dict, aad: bytes | None = None) -> dict:\n        aes: Final = AESGCM(self.key)\n        nonce: Final = base64.b64decode(enc[\"nonce\"])\n        ct: Final = base64.b64decode(enc[\"ciphertext\"])","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/app_crypto.py#L1-L30","documentation":"Error \"Master key must be 32 bytes for AES-256-GCM\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/litellm_core_utils/app_crypto.py:12 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a 32-byte master key for AES-256-GCM."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}