Overview
The Key Management Service uses asymmetric RSA encryption to protect sensitive data. Each client device receives a unique RSA key pair consisting of a public key for encryption and a private key for decryption.The service uses RSA-2048 encryption with PKCS1_OAEP_PADDING for optimal security and compatibility.
RSA Key Pair Generation
Technical Specifications
Keys are generated using Node.js’s nativecrypto module with the following configuration:
Reference: crypto.ts:19-29
Key Generation Parameters
| Parameter | Value | Description |
|---|---|---|
| Algorithm | RSA | Asymmetric encryption algorithm |
| Modulus Length | 2048 bits | Key size providing strong security |
| Public Key Type | SPKI | Subject Public Key Info format |
| Private Key Type | PKCS8 | Private Key Information Syntax Standard |
| Format | PEM | Privacy-Enhanced Mail encoding |
Public and Private Key Usage
Public Key (Client-Side)
The public key is distributed to client applications and used to encrypt sensitive data before transmission:Reference: crypto.ts:44-59
- Encrypted data is returned as a base64-encoded string
- Uses PKCS1_OAEP_PADDING for enhanced security
- Public keys can be safely shared with clients
- Each encryption produces different ciphertext (non-deterministic)
Private Key (Server-Side Only)
The private key remains secure on the server and is used to decrypt data encrypted with the corresponding public key:Reference: crypto.ts:68-83
Key Storage and Management
Database Schema
Each encryption key is stored with comprehensive metadata:Reference: encryption.service.ts:68-78
Key Identification
Each key pair receives a unique identifier combining timestamp and randomness:- Globally unique identifiers
- Chronological ordering
- Cryptographic randomness to prevent prediction
Key Lifecycle
1. Key Generation
1. Key Generation
When a client requests an encryption key, the service:
- Checks for existing valid keys for the device
- If a valid key exists, returns it (avoiding unnecessary generation)
- Otherwise, generates a new RSA-2048 key pair
- Stores both keys in the database with expiration date
- Returns the public key and keyId to the client
2. Key Usage
2. Key Usage
During the key’s lifetime:
- Client: Uses public key to encrypt sensitive data (passcodes, PINs, etc.)
- Server: Uses private key to decrypt received data
- Validation: Each decryption checks if the key has expired
- Monitoring: All operations are logged for security auditing
3. Key Expiration
3. Key Expiration
Keys automatically expire after a configured period (default: 30 days):Expired keys are rejected during decryption operations.Reference: encryption.service.ts:63-66
4. Key Deprecation
4. Key Deprecation
Expired or problematic keys are marked as deprecated:
- Prevents use in new operations
- Retained for a grace period (default: 90 days)
- Eventually deleted from the database
Encryption Workflow
Security Considerations
Best Practices
- Never expose private keys: Private keys should never be transmitted to clients or logged
- Validate key expiration: Always check if a key has expired before use
- Use key rotation: Regular rotation limits the impact of potential key compromise
- Monitor key usage: Track encryption/decryption operations for anomalies
- Limit data size: Enforce maximum encrypted data size to prevent resource exhaustion
Related Topics
Key Rotation
Learn about automated key rotation and lifecycle management
Security Measures
Explore security features including rate limiting and validation