Skip to content

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.

License

Notifications You must be signed in to change notification settings

mavbozo/AndroidSecureCrypto

Repository files navigation

AndroidSecureCrypto

License: MIT API

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.

Features

  • 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

Installation

Add the dependency to your app's build.gradle.kts:

dependencies {
    implementation("com.mavbozo.crypto:androidsecurecrypto:0.3.0")
}

Dokka Docs

Quick Start

Random Number Generation

// 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)

Encryption

// 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)
}

Documentation

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

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.

Resources

License

Security policy

Stars

Watchers

Forks

Languages