@@ -168,53 +168,112 @@ All examples demonstrate:
168168
169169### Initialize Biometric Service
170170``` dart
171- import 'package:biometric_signature/key_material .dart';
171+ import 'package:biometric_signature/biometric_signature .dart';
172172
173173final biometric = BiometricSignature();
174174
175175// Check availability
176- final available = await biometric.biometricAuthAvailable();
176+ final availability = await biometric.biometricAuthAvailable();
177+ if (availability.canAuthenticate ?? false) {
178+ print('Biometrics available: ${availability.availableBiometrics}');
179+ }
177180
178- // Create keys
181+ // Create keys (RSA by default)
179182final keyResult = await biometric.createKeys(
180183 keyFormat: KeyFormat.pem,
181- androidConfig: AndroidConfig(
182- useDeviceCredentials: false,
183- signatureType: AndroidSignatureType.RSA ,
184- ) ,
185- iosConfig: IosConfig(
186- useDeviceCredentials: false ,
187- signatureType: IOSSignatureType.RSA,
184+ promptMessage: 'Authenticate to create keys',
185+ config: CreateKeysConfig(
186+ signatureType: SignatureType.rsa ,
187+ useDeviceCredentials: true ,
188+ setInvalidatedByBiometricEnrollment: true,
189+ enforceBiometric: true ,
190+ enableDecryption: false, // Android only
188191 ),
189192);
190193
191- final pemPublicKey = keyResult?.publicKey.asString();
194+ if (keyResult.code == BiometricError.success) {
195+ print('Public Key: ${keyResult.publicKey}');
196+ }
197+ ```
198+
199+ ### Get Key Info
200+ ``` dart
201+ // Check key existence with metadata
202+ final info = await biometric.getKeyInfo(
203+ checkValidity: true,
204+ keyFormat: KeyFormat.pem,
205+ );
206+
207+ if (info.exists && (info.isValid ?? true)) {
208+ print('Algorithm: ${info.algorithm}, Size: ${info.keySize} bits');
209+ print('Hybrid Mode: ${info.isHybridMode}');
210+ print('Public Key: ${info.publicKey}');
211+ }
192212```
193213
194214### Sign Data
195215``` dart
196- final signatureResult = await biometric.createSignature(
197- SignatureOptions(
198- payload: 'data_to_sign',
199- promptMessage: 'Authenticate to continue',
200- keyFormat: KeyFormat.raw,
216+ final result = await biometric.createSignature(
217+ payload: 'data_to_sign',
218+ promptMessage: 'Authenticate to sign',
219+ signatureFormat: SignatureFormat.base64,
220+ keyFormat: KeyFormat.pem,
221+ config: CreateSignatureConfig(
222+ allowDeviceCredentials: true,
201223 ),
202224);
203225
204- final signatureBase64 = signatureResult?.signature.toBase64();
226+ if (result.code == BiometricError.success) {
227+ print('Signature: ${result.signature}');
228+ }
229+ ```
230+
231+ ### Decrypt Data
232+ ``` dart
233+ final decryptResult = await biometric.decrypt(
234+ payload: encryptedBase64,
235+ payloadFormat: PayloadFormat.base64,
236+ promptMessage: 'Authenticate to decrypt',
237+ config: DecryptConfig(
238+ allowDeviceCredentials: false,
239+ ),
240+ );
241+
242+ if (decryptResult.code == BiometricError.success) {
243+ print('Decrypted: ${decryptResult.decryptedData}');
244+ }
205245```
206246
207247### Error Handling
208248``` dart
209- try {
210- final signatureResult = await biometric.createSignature(options);
211- final signatureHex = signatureResult?.signature.toHex();
212- } on PlatformException catch (e) {
213- if (e.code == 'AUTH_FAILED') {
214- // Handle authentication failure
215- } else if (e.code == 'CANCELLED') {
216- // Handle user cancellation
217- }
249+ final result = await biometric.createSignature(
250+ payload: 'data_to_sign',
251+ promptMessage: 'Authenticate',
252+ );
253+
254+ switch (result.code) {
255+ case BiometricError.success:
256+ print('Signed: ${result.signature}');
257+ break;
258+ case BiometricError.userCanceled:
259+ print('User cancelled authentication');
260+ break;
261+ case BiometricError.keyInvalidated:
262+ print('Key invalidated - re-enrollment required');
263+ break;
264+ case BiometricError.lockedOut:
265+ print('Too many attempts - locked out');
266+ break;
267+ default:
268+ print('Error: ${result.code} - ${result.error}');
269+ }
270+ ```
271+
272+ ### Delete Keys
273+ ``` dart
274+ final deleted = await biometric.deleteKeys();
275+ if (deleted) {
276+ print('All biometric keys removed');
218277}
219278```
220279
@@ -232,7 +291,7 @@ Found an issue or want to improve an example? Contributions are welcome!
232291
2332921 . Fork the repository
2342932 . Create your feature branch
235- 3 . Test your changes on both platforms
294+ 3 . Test your changes on all platforms
2362954 . Submit a pull request
237296
238297## 📄 License
0 commit comments