A comprehensive, hardware-backed cryptography library for Android applications. The library aims to provide a complete suite of cryptographic operations with strong security guarantees and ergonomic Kotlin-first API design.
-
Secure Random Number Generation
- Hardware-backed entropy generation (when available)
- Secure memory handling with automatic cleanup
- Enhanced entropy mixing using Android Keystore
- Automatic quality detection and fallback mechanisms
-
Symmetric Encryption (AES-GCM)
- Authenticated encryption with associated data (AEAD)
- Hardware acceleration when available
- Automatic IV management and tag validation
- String, byte array, and file encryption support
Add the dependency to your app's build.gradle.kts
:
dependencies {
implementation("com.mavbozo.crypto:androidsecurecrypto:0.3.0")
}
// Generate random bytes with automatic cleanup
val bytesResult = Random.generateBytes(32)
bytesResult.fold(
onSuccess = { bytes ->
try {
// Use the bytes
} finally {
bytes.fill(0) // Clean up
}
},
onFailure = { error ->
// Handle error
}
)
// Generate hex string
val hexResult = Random.generateBytesAsHex(32)
// String encryption
val key = Random.generateBytes(32).getOrThrow()
try {
val encrypted = Cipher.encryptString(key, "sensitive data")
.getOrThrow()
val decrypted = Cipher.decryptString(key, encrypted)
.getOrThrow()
} finally {
key.fill(0)
}
- File bug reports and feature requests via GitHub Issues
- For security issues, see our Security Policy
- Questions? open github Issues or email mavbozo@pm.me
This project is licensed under the MIT License - see the LICENSE file for details.