Key Generation¶
The Key Generation feature allows users to generate encryption keys for various algorithms and manage them locally.
Supported Algorithms¶
- AES-128: 128-bit Advanced Encryption Standard
- AES-192: 192-bit Advanced Encryption Standard
- AES-256: 256-bit Advanced Encryption Standard
- ChaCha20-256: 256-bit ChaCha20 stream cipher
Features¶
Generate Key¶
- Select an encryption algorithm
- Click “Generate Key” button
- Key is generated using secure random number generation
- Generated key is displayed in Base64 format
Save Key¶
Generated keys are automatically saved to local storage (SharedPreferences).
View Saved Keys¶
All saved keys are displayed in a list showing: - Key ID (first 8 characters) - Algorithm type - Full key (Base64 encoded)
Delete Key¶
- Delete individual keys
- Delete all keys at once
Copy to Clipboard¶
Copy generated or saved keys to clipboard for easy sharing.
Usage¶
Generating a Key¶
// In ViewModel
fun generateKey(algorithm: EncryptionAlgorithm) {
viewModelScope.launch {
generateKeyCommand.handle(
AesGenerateAndSaveKeyCommand(algorithm)
).fold(
onSuccess = { keyView ->
// Update UI state
},
onFailure = { error ->
// Handle error
}
)
}
}
Loading Saved Keys¶
fun loadKeys() {
viewModelScope.launch {
readAllKeysQuery.handle(ReadAllKeysQuery())
.fold(
onSuccess = { keys ->
// Update UI state
},
onFailure = { error ->
// Handle error
}
)
}
}
Security Considerations¶
Key Storage
Currently, keys are stored in SharedPreferences. For production use:
- Implement Android Keystore for secure storage
- Encrypt keys before storing
- Implement proper access controls
UI Components¶
- AlgorithmSelectionCard: Select encryption algorithm
- GenerateKeyButton: Trigger key generation
- GeneratedKeyCard: Display generated key
- SavedKeysSection: List of saved keys
- DeleteAllKeysDialog: Confirm deletion
Learn More¶
- Encryption & Decryption - Using generated keys
- Architecture - Domain Layer - Key generation logic
- Architecture - Application Layer - Command handlers