Encryption Architecture
Zero-Knowledge Design
Bitwarden’s security model ensures:- Client-side encryption: All encryption/decryption happens on the client
- Server-blind storage: Server stores only encrypted data
- Master password never transmitted: Used only locally to derive encryption keys
- Account recovery requires user action: Server cannot decrypt user data
Encryption Types
Bitwarden supports multiple encryption schemes: Implementation:src/Core/Utilities/EncryptedStringAttribute.cs:14
| Type | Algorithm | Key Size | HMAC | Use Case |
|---|---|---|---|---|
| AesCbc256_B64 | AES-CBC | 256-bit | No | Legacy |
| AesCbc128_HmacSha256_B64 | AES-CBC | 128-bit | SHA-256 | Standard |
| AesCbc256_HmacSha256_B64 | AES-CBC | 256-bit | SHA-256 | Enhanced |
| Rsa2048_OaepSha256_B64 | RSA-OAEP | 2048-bit | No | Asymmetric |
Encrypted String Format
Structure:2= Encryption type (AesCbc128_HmacSha256_B64)abc123= Base64-encoded IVdef456= Base64-encoded ciphertextghi789= Base64-encoded MAC
src/Core/Utilities/EncryptedStringAttribute.cs:60
User Encryption Keys
Account Encryption Versions
Bitwarden supports two account encryption schemes:V1 Encryption (Legacy)
Key Derivation:- Master Password → PBKDF2 → Master Key
- Master Key → HKDF → Encryption Key + MAC Key
- Master Key → PBKDF2 → Master Password Hash (for authentication)
- Encrypted symmetric key
- Public encryption key (RSA 2048-bit)
- Private encryption key (encrypted with symmetric key)
V2 Encryption (Current)
Enhanced Features:- Separate signature keys (Ed25519 or RSA 2048-bit)
- Improved key derivation
- Support for trusted device encryption
- Account recovery capabilities
src/Core/KeyManagement/Models/Data/UserAccountKeysData.cs
Key Rotation
Bitwarden supports cryptographic key rotation: When to Rotate:- Master password change
- Suspected key compromise
- Compliance requirements
- Migration to V2 encryption
Implementation:
src/Core/KeyManagement/Kdf/Implementations/ChangeKdfCommand.cs
Organization Encryption
Organization Keys
Key Structure:- Organization key encrypted with each user’s public key
- User decrypts org key with their private key
- User uses org key to decrypt organization items
Collection Encryption
Collections use the organization key:- Collection membership determines access
- Encryption key shared via organization membership
- Permissions enforced server-side
- Data remains encrypted at rest
Data Protection Keys
ASP.NET Core Data Protection
Bitwarden uses Data Protection for server-side sensitive data: Configuration:src/Core/Settings/GlobalSettings.cs:548
Protected Data Types
Server-side protection for:- Temporary tokens (email verification, password reset)
- Session state
- Anti-forgery tokens
- Organization sponsorship offers
- Provider user invitations
- Emergency access invitations
src/Core/Tokens/DataProtectorTokenFactory.cs
Data Protection Purposes
Purpose Strings:| Purpose | Use Case | Implementation |
|---|---|---|
| OrganizationServiceDataProtector | Organization user invites | OrgUserInviteTokenable.cs:20 |
| ProviderServiceDataProtector | Provider user invites | RegisterUserCommand.cs:80 |
| RegistrationEmailVerificationTokenDataProtector | Email verification | RegistrationEmailVerificationTokenable.cs:18 |
| SsoTokenDataProtector | SSO session tokens | SsoTokenable.cs:13 |
| WebAuthnCredentialCreateDataProtector | WebAuthn credential creation | WebAuthnCredentialCreateOptionsTokenable.cs:16 |
| EmergencyAccessInviteDataProtector | Emergency access invites | EmergencyAccessService.cs |
Certificate Management
Identity Server Certificates
Signing Certificates:- RSA 2048-bit or higher
- Valid for signing operations
- Stored securely with restricted permissions
Data Protection Certificates
Configuration:Certificate Storage
Secure Storage:Encryption at Rest
Database Encryption
SQL Server Transparent Data Encryption (TDE): Verification:File Storage Encryption
Local Storage:- Storage Service Encryption (SSE)
- Customer-managed keys (CMK) in Azure Key Vault
- Private endpoints for secure access
Encryption Best Practices
Key Management
Key Generation
- Use cryptographically secure random number generators
- Generate keys with appropriate length (AES-256, RSA-2048+)
- Never reuse keys across different purposes
Key Storage
- Store keys encrypted when at rest
- Use hardware security modules (HSM) for production
- Implement key rotation policies
- Backup encryption keys securely
Key Distribution
- Use asymmetric encryption for key exchange
- Validate recipient identity before sharing
- Implement secure channel for key transmission
- Audit all key access and distribution
Key Destruction
- Securely delete keys when no longer needed
- Use cryptographic erasure techniques
- Maintain key destruction audit trail
- Verify data encrypted with key is also destroyed
Cryptographic Operations
Do’s:- Use authenticated encryption (AES-GCM, AES-CBC + HMAC)
- Generate unique IVs for each encryption operation
- Use constant-time comparison for MACs
- Implement proper error handling without leaking information
- Never roll your own crypto
- Don’t use ECB mode
- Don’t reuse IVs with the same key
- Don’t use MD5 or SHA-1 for security purposes
- Don’t store passwords in reversible encryption
Algorithm Selection
Recommended:| Use Case | Algorithm | Key Size |
|---|---|---|
| Symmetric encryption | AES-CBC + HMAC-SHA256 | 256-bit |
| Symmetric encryption (AEAD) | AES-GCM | 256-bit |
| Asymmetric encryption | RSA-OAEP | 2048-bit+ |
| Digital signatures | RSA-PSS or Ed25519 | 2048-bit+ / 256-bit |
| Key derivation | PBKDF2 or Argon2id | N/A |
| Hashing | SHA-256 or SHA-512 | N/A |
Troubleshooting Encryption Issues
Invalid Encryption String
Error:Invalid encryption string format
Causes:
- Corrupted database data
- Incomplete migration
- Incorrect encryption type
Key Mismatch Errors
Symptoms:- Cannot decrypt vault items
- “Invalid key” errors
- Items appear empty
- Verify user has correct encryption key
- Check for key rotation issues
- Validate organization membership
- Restore from backup if corruption detected
Certificate Issues
Error:Certificate not found or Invalid certificate
Troubleshooting:
Migration to V2 Encryption
Migration Process
For users still on V1 encryption:Initiate Migration
User must log in to web vault and complete migration flow:
- Verify master password
- Generate new V2 keys
- Re-encrypt vault data