sinew_security 1.1.0
sinew_security: ^1.1.0 copied to clipboard
FieldCipher and BiometricVault on vetted crypto per platform.
sinew_security #
FieldCipher and BiometricVault on vetted crypto per platform.
Field encryption and a biometric vault that never invent a cipher: AES-256-GCM from vetted libraries on every platform, keys kept in the platform's key storage, and a fresh nonce for every value.
Features #
FieldCipher:encryptanddecryptwith acontextbound as associated data, androtateKeythat keeps old values readableBiometricVault: store a secret behind a biometric match withstore, release it only by a real match withunlock, and report why not as a user outcome, not an error- One value layout on every platform, so any platform decrypts any other's output
Getting started #
flutter pub add sinew_security
Usage #
final cipher = await FieldCipher.create();
final sealed = await cipher.encrypt('Alice', context: 'customer:42');
final plain = await cipher.decrypt(sealed, context: 'customer:42');
A value decrypted with another context fails with DecryptionFailed, so a value copied to another field doesn't decrypt.
final vault = BiometricVault.create();
if (await vault.availability() == BiometricAvailability.available) {
await vault.store(refreshToken, reason: 'Sign in with biometrics next time');
}
final unlocked = await vault.unlock(reason: 'Sign in');
Requirements #
FieldCipher uses webcrypto: Google's BoringSSL on native platforms, the
browser's Web Crypto on the web. BoringSSL is compiled from source by Dart's native-assets build, so every machine that
builds an app using this package needs CMake on its PATH (macOS: brew install cmake; Ubuntu: apt install cmake;
or the CMake that Android Studio's SDK Manager installs, under <sdk>/cmake/<version>/bin). The first build per
platform takes a minute or two longer; later builds are cached. GitHub's hosted runners already have CMake.
The keys are kept with flutter_secure_storage; its platform setup
applies (on macOS, the Keychain Sharing entitlement).
BiometricVault setup #
BiometricVault is a plugin with native Android and iOS code. Each app needs:
- Android:
MainActivityextendsFlutterFragmentActivity(BiometricPromptneeds aFragmentActivity); without it,storeandunlockreturnBiometricFailed(unavailable)and log the fix. Exclude the vault's shared preferences (sinew.security.biometric.xml) from cloud backup and device transfer indata_extraction_rules.xml; the key can't leave the device anyway. - iOS:
NSFaceIDUsageDescriptioninInfo.plist. - macOS: the Keychain Sharing entitlement, for
FieldCipher's keys. The vault is unavailable on desktop and web.
On Android, store shows the prompt (the key needs a match to encrypt too); iOS stores without one. A secret is
released only by a real match: no prompt sits in front of a normal read.
Related packages #
Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.
Documentation #
- Usage docs: sinew.srctool.com
- API reference: pub.dev/documentation/sinew_security
- Source and issues: srctool/sinew-dart
- Design and decisions: the Guide
License #
Apache 2.0, see LICENSE.