jc_crypto_hashing
A Flutter plugin providing Android JCA (Java Cryptography Architecture) backend for cryptographic operations.
This package uses package:jnigen to call native Android Java APIs directly from Dart, avoiding the need for bundling external native binaries like BoringSSL for basic cryptographic tasks on Android.
Features
- Hashing: SHA-256, SHA-512
- HMAC: HMAC-SHA256
- AES-GCM: Encryption, Decryption, and Key Generation
- Additional Authenticated Data (AAD): Supported for AES-GCM
- Hardware-Backed Keys: Support for Android Keystore (KeyStore aliases)
- Performance: Optimized using ThreadLocal Cipher reuse
Usage
import 'package:jc_crypto_hashing/jc_crypto_hashing.dart';
import 'dart:typed_data';
void main() async {
final crypto = CryptoJCA();
// 1. Generation of a secure Software Key
final key = await crypto.generateSoftwareKey(bits: 256);
// 2. Prepare data, IV and AAD
final data = Uint8List.fromList("Sensitive Content".codeUnits);
final iv = CryptoJCA.generateIv();
final aad = Uint8List.fromList("AAD-String".codeUnits);
// 3. Encrypt using the CryptoKey object
final encrypted = await crypto.aesGcmEncrypt(
data,
iv,
cryptoKey: key,
additionalData: aad
);
// 4. Decrypt
final decrypted = await crypto.aesGcmDecrypt(
encrypted,
iv,
cryptoKey: key,
additionalData: aad
);
print(String.fromCharCodes(decrypted)); // "Sensitive Content"
}
Using Android Keystore (Hardware Backed)
// Generate a key that stays in the security hardware
final keystoreKey = await crypto.generateKeystoreKey("my_identifier");
// Encrypt - the raw key never enters Dart/user memory
final encrypted = await crypto.aesGcmEncrypt(data, iv, cryptoKey: keystoreKey);
Platform Support
This package is specifically designed for Android. It is intended as a high-performance, system-native alternative for package:webcrypto and other cryptographic needs.
Setup
No special setup is required. The package automatically handles the JNI bindings and Java code and bundles them into your Android APK/AAB.