https://github.com/prongbang/local_auth_signature
Generate key pair and signing (NIST P-256 EC key pair using ECDSA) using Local Authentication for Android and iOS.
https://github.com/prongbang/local_auth_signature
android flutter flutter-plugin ios keypair local-auth-signature sign verify
Last synced: 5 months ago
JSON representation
Generate key pair and signing (NIST P-256 EC key pair using ECDSA) using Local Authentication for Android and iOS.
- Host: GitHub
- URL: https://github.com/prongbang/local_auth_signature
- Owner: prongbang
- License: mit
- Created: 2022-12-23T07:14:42.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2025-01-22T07:40:52.000Z (9 months ago)
- Last Synced: 2025-04-21T10:09:48.593Z (6 months ago)
- Topics: android, flutter, flutter-plugin, ios, keypair, local-auth-signature, sign, verify
- Language: Kotlin
- Homepage: https://pub.dev/packages/local_auth_signature
- Size: 474 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# local_auth_signature 🔐
[](https://pub.dartlang.org/packages/local_auth_signature)
[](https://flutter.dev)
[](https://flutter.dev/multi-platform)
[](https://opensource.org/licenses/MIT)> Generate key pairs and cryptographic signatures using NIST P-256 EC key pair with ECDSA, protected by biometric authentication for Flutter (Android & iOS).

## ✨ Features
- 🔑 **Secure Key Generation** - Generate NIST P-256 EC key pairs
- 🔒 **Biometric Protection** - Keys protected by fingerprint or Face ID
- ✍️ **Digital Signatures** - Create and verify ECDSA signatures
- 📱 **Cross-Platform** - Works on both Android and iOS
- 🔄 **Biometric Change Detection** - Detect when biometric data changes
- 💾 **Secure Storage** - Keys stored securely in platform keystore## 📦 Installation
Add to your `pubspec.yaml`:
```yaml
dependencies:
local_auth_signature: ^1.0.12
```Then run:
```bash
flutter pub get
```## 🚀 Quick Start
### 1. Import the Package
```dart
import 'package:local_auth_signature/local_auth_signature.dart';
```### 2. Initialize
```dart
final _localAuthSignature = LocalAuthSignature.instance;
final _key = 'com.yourapp.signatureKey';
```### 3. Generate Key Pair
```dart
try {
final publicKey = await _localAuthSignature.createKeyPair(
_key,
AndroidPromptInfo(
title: 'BIOMETRIC',
subtitle: 'Please allow biometric',
negativeButton: 'CANCEL',
),
IOSPromptInfo(reason: 'Please allow biometric'),
);
print('Public Key: $publicKey');
} on PlatformException catch (e) {
print('Error: ${e.code}');
}
```## 📱 Platform Setup
### 🤖 Android Setup
1. Update `MainActivity.kt`:
```kotlin
import io.flutter.embedding.android.FlutterFragmentActivityclass MainActivity : FlutterFragmentActivity()
```2. Add permissions to `AndroidManifest.xml`:
```xml
```
3. Add JitPack repository to `build.gradle`:
```groovy
buildscript {
repositories {
maven { url "https://jitpack.io" }
}
}allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
```### 🍎 iOS Setup
Add to your `Info.plist`:
```xml
NSFaceIDUsageDescription
This application wants to access your TouchID or FaceID```
## 📚 API Reference
### Biometric Changes
#### Check if Biometrics Changed
```dart
final bool hasChanged = await _localAuthSignature.isBiometricChanged(_key);
```#### Reset Biometric Status (iOS only)
```dart
await _localAuthSignature.resetBiometricChanged();
```### Key Management
#### Create Key Pair
```dart
final String publicKey = await _localAuthSignature.createKeyPair(
keyName,
androidPrompt,
iosPrompt,
);
```#### Sign Data
```dart
final String signature = await _localAuthSignature.sign(
keyName,
payload,
androidPrompt,
iosPrompt,
);
```#### Verify Signature
```dart
final bool isValid = await _localAuthSignature.verify(
keyName,
payload,
signature,
androidPrompt,
iosPrompt,
);
```## 💡 Complete Example
```dart
class BiometricSignature {
final _localAuthSignature = LocalAuthSignature.instance;
final _key = 'com.yourapp.biometric.key';
final _payload = 'Hello, World!';
Future demonstrateSignature() async {
try {
// Check if biometrics changed
final changed = await _localAuthSignature.isBiometricChanged(_key);
if (changed) {
// Handle biometric enrollment changes
print('Biometrics have changed!');
}
// Create key pair
final publicKey = await _localAuthSignature.createKeyPair(
_key,
AndroidPromptInfo(
title: 'Create Key',
subtitle: 'Authenticate to create secure key',
negativeButton: 'Cancel',
),
IOSPromptInfo(reason: 'Authenticate to create secure key'),
);
print('Public Key: $publicKey');
// Sign data
final signature = await _localAuthSignature.sign(
_key,
_payload,
AndroidPromptInfo(
title: 'Sign Data',
subtitle: 'Authenticate to sign',
negativeButton: 'Cancel',
),
IOSPromptInfo(reason: 'Authenticate to sign'),
);
print('Signature: $signature');
// Verify signature
final verified = await _localAuthSignature.verify(
_key,
_payload,
signature,
AndroidPromptInfo(
title: 'Verify Signature',
subtitle: 'Authenticate to verify',
negativeButton: 'Cancel',
),
IOSPromptInfo(reason: 'Authenticate to verify'),
);
print('Verified: $verified');
} on PlatformException catch (e) {
handleError(e);
}
}
void handleError(PlatformException e) {
switch (e.code) {
case 'auth_failed':
print('Authentication failed');
break;
case 'not_available':
print('Biometric authentication not available');
break;
case 'user_cancel':
print('User cancelled authentication');
break;
default:
print('Error: ${e.code} - ${e.message}');
}
}
}
```## 🔍 Error Handling
Common error codes:
| Code | Description |
|------|-------------|
| `auth_failed` | Authentication failed |
| `not_available` | Biometric authentication not available |
| `user_cancel` | User cancelled authentication |
| `key_not_found` | Key not found in keystore |
| `biometric_changed` | Biometric enrollment has changed |## 🔒 Security Considerations
1. **Key Storage**: Private keys are stored in platform-specific secure storage
2. **Biometric Protection**: Keys require biometric authentication to use
3. **Change Detection**: Keys become invalid when biometric data changes
4. **Platform Security**: Leverages Android Keystore and iOS Secure Enclave## 🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## 📄 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## 💖 Support the Project
If you find this package helpful, please consider supporting it:
[](https://www.buymeacoffee.com/prongbang)
## 🔗 Related Projects
- [Android Biometric Signature](https://github.com/prongbang/android-biometric-signature)
- [SignatureBiometricSwift](https://github.com/prongbang/SignatureBiometricSwift)---