Overview
The Key Management Service uses asymmetric encryption:- Client-side: Encrypts sensitive data using the public key
- Server-side: Decrypts data using the corresponding private key
- Algorithm: RSA-2048 with PKCS1_OAEP padding
- Encoding: Base64 for transport
Encryption/Decryption Flow
Client-Side Encryption
Encryption Implementation
Use the RSA public key to encrypt data before sending to the server:Usage Example
Browser Compatibility
For browser environments, use the Web Crypto API:Server-Side Decryption
Decryption Implementation
Decryption Service
The EncryptionService handles secure decryption with validation:Private Key Retrieval
Private keys are securely retrieved and validated:Data Size Validation
The service enforces maximum encrypted data size to prevent abuse:Testing Encryption (Development Only)
The service provides a development mutation to test encryption like a client:Implementation
Complete Example
Security Considerations
RSA-2048 Encryption
Uses industry-standard 2048-bit RSA keys with PKCS1_OAEP padding for secure encryption.
Private Keys Never Exposed
Private keys remain on the server and are never transmitted to clients.
Key Expiration
Keys automatically expire after 30 days, enforcing regular rotation.
Size Validation
Encrypted data is validated to prevent oversized payloads (max 2048 bytes).
Error Handling
Common Errors
Client-Side Error Handling
Performance Considerations
RSA Data Size Limits
RSA-2048 can encrypt a maximum of 214 bytes of plaintext data with PKCS1_OAEP padding:- Key size: 2048 bits (256 bytes)
- PKCS1_OAEP overhead: ~42 bytes
- Maximum plaintext: ~214 bytes
- Use hybrid encryption (RSA + AES)
- Split data into smaller chunks
- Hash data and encrypt the hash
Encryption Speed
- Client-side encryption: ~1-5ms per operation
- Server-side decryption: ~2-10ms per operation
Monitoring
All decryption operations are automatically logged for monitoring:Next Steps
Authentication
Implement secure passcode and PIN authentication
Monitoring
Track encryption metrics and monitor system health