Overview
Azen encrypts all memory content at rest using AES-256-GCM (Advanced Encryption Standard with Galois/Counter Mode). This ensures that stored memories are cryptographically secure and tamper-proof.Why AES-256-GCM?
GCM (Galois/Counter Mode) provides:- Confidentiality: 256-bit AES encryption
- Authenticity: Built-in authentication tag prevents tampering
- Performance: Hardware-accelerated on modern CPUs
- Security: Authenticated encryption with associated data (AEAD)
AES-256-GCM is approved by NIST and widely used in secure protocols like TLS 1.3.
Implementation
The encryption module is implemented inapps/api/src/lib/encrypt.ts using Node.js crypto primitives.
Master Key Configuration
The system uses a single master key for all encryption operations:Generating a Master Key
To generate a secure master key:Encryption Process
TheencryptText function (apps/api/src/lib/encrypt.ts:12-28) encrypts plaintext and returns three components:
Encryption Components
| Component | Purpose | Size | Encoding |
|---|---|---|---|
| Ciphertext | Encrypted data | Variable | Base64 |
| IV (Initialization Vector) | Ensures uniqueness | 12 bytes | Base64 |
| Tag | Authentication tag | 16 bytes | Base64 |
Why 12-byte IV?
GCM mode requires a 96-bit (12-byte) IV for optimal security:- Standard recommended size for AES-GCM
- Must be unique for each encryption with the same key
- Randomly generated using
crypto.randomBytes(12)
Each memory gets a unique IV, even if the plaintext content is identical. This prevents pattern analysis attacks.
Authentication Tag
The 16-byte authentication tag is computed over the ciphertext and provides:- Integrity: Detects any modification to the ciphertext
- Authenticity: Proves the data was encrypted with the correct key
Decryption Process
ThedecryptText function (apps/api/src/lib/encrypt.ts:30-49) reverses the encryption:
Decryption Flow
Error Handling
Decryption can fail if:- The authentication tag is invalid (data was tampered)
- The IV is incorrect
- The master key is wrong
- The ciphertext is corrupted
decipher.final().
Storage in Database
Encrypted memories are stored in theMemory table with three fields (packages/db/src/db/schema.ts:239-241):
Example Database Record
Usage in API Endpoints
Memory Creation
Fromapps/api/src/routes/memory.ts:41:
Memory Retrieval
Fromapps/api/src/routes/memory.ts:134:
Search Results
Fromapps/api/src/routes/search.ts:80:
Decryption happens at query time. The plaintext never leaves the API server’s memory.
Security Considerations
What is Encrypted?
Encrypted:- Memory content (plaintext stored in
Memorytable) - Stored at rest in PostgreSQL
- Memory IDs (UUIDs)
- User IDs and organization IDs (needed for queries)
- Timestamps and metadata
- Vector embeddings (stored in Pinecone)
Threat Model
Protection Against:- Database breach (ciphertext is useless without master key)
- Unauthorized database access (read-only access reveals no plaintext)
- Storage media theft (encrypted at rest)
- Compromise of the master key
- Memory dumps from the API server process
- Attacks on the embedding vectors
- Side-channel attacks during decryption
Key Rotation Strategy
To rotate the master key:- Generate a new master key
- Deploy code that can decrypt with old key, encrypt with new key
- Background job to re-encrypt all memories:
- Decrypt with old key
- Encrypt with new key
- Update database record
- Remove old key after all data is re-encrypted
Key rotation is not currently implemented but can be added using a
keyVersion field in the Memory table.Performance Impact
Encryption Overhead
- Encryption: ~0.1-0.5ms per memory (depends on text size)
- Decryption: ~0.1-0.5ms per memory
- Hardware Acceleration: Modern CPUs have AES-NI instructions
At Scale
- Encrypting 1000 memories: ~100-500ms
- Decrypting 1000 memories: ~100-500ms
- Negligible compared to network and database I/O
Compliance and Standards
AES-256-GCM meets requirements for:- NIST: Approved for use in Federal Information Processing Standards (FIPS)
- GDPR: Provides “encryption at rest” for personal data
- HIPAA: Satisfies “encryption of data at rest” requirements
- SOC 2: Demonstrates data protection controls
Azen’s encryption implementation uses standard Node.js crypto module, which is based on OpenSSL and FIPS-validated.
Related Concepts
- Memory System - How encryption fits into the memory lifecycle
- Semantic Search - Why embeddings are not encrypted
- Organizations - How encryption works with multi-tenancy

