Add pbkdf2 and exceptions support
This commit is contained in:
parent
2a5c719c2e
commit
900178ba82
@ -4,6 +4,7 @@ import 'dart:async';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:native_crypto/exceptions.dart';
|
||||||
|
|
||||||
/// [Sources]
|
/// [Sources]
|
||||||
/// Plugin class.
|
/// Plugin class.
|
||||||
@ -16,14 +17,38 @@ class NativeCrypto {
|
|||||||
static const MethodChannel _channel =
|
static const MethodChannel _channel =
|
||||||
const MethodChannel('native.crypto.helper');
|
const MethodChannel('native.crypto.helper');
|
||||||
|
|
||||||
|
/// PBKDF2.
|
||||||
|
///
|
||||||
|
/// [keyLength] is in Bytes.
|
||||||
|
/// It returns an `Uint8List`.
|
||||||
|
Future<Uint8List> pbkdf2(String password, String salt, {int keyLength: 32, int iteration: 10000}) async {
|
||||||
|
Uint8List key;
|
||||||
|
try {
|
||||||
|
key = await _channel.invokeMethod('pbkdf2', <String, dynamic>{
|
||||||
|
'password': password,
|
||||||
|
'salt': salt,
|
||||||
|
'keyLength': keyLength,
|
||||||
|
'iteration': iteration,
|
||||||
|
});
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates AES key.
|
/// Generates AES key.
|
||||||
///
|
///
|
||||||
/// [size] is in bits, 128, 192 or 256.
|
/// [size] is in bits, 128, 192 or 256.
|
||||||
/// It returns an `Uint8List`.
|
/// It returns an `Uint8List`.
|
||||||
Future<Uint8List> symKeygen(int size) async {
|
Future<Uint8List> symKeygen(int size) async {
|
||||||
final Uint8List aesKey = await _channel.invokeMethod('symKeygen', <String, dynamic>{
|
Uint8List aesKey;
|
||||||
'size': size
|
try {
|
||||||
|
aesKey = await _channel.invokeMethod('symKeygen', <String, dynamic>{
|
||||||
|
'size': size,
|
||||||
});
|
});
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
return aesKey;
|
return aesKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,11 +73,15 @@ class NativeCrypto {
|
|||||||
/// with encrypted cipher as first and IV as second member.
|
/// with encrypted cipher as first and IV as second member.
|
||||||
Future<Uint8List> symDecrypt(
|
Future<Uint8List> symDecrypt(
|
||||||
List<Uint8List> payloadbytes, Uint8List aesKey) async {
|
List<Uint8List> payloadbytes, Uint8List aesKey) async {
|
||||||
final Uint8List decryptedPayload =
|
Uint8List decryptedPayload;
|
||||||
await _channel.invokeMethod('symDecrypt', <String, dynamic>{
|
try {
|
||||||
|
decryptedPayload = await _channel.invokeMethod('symDecrypt', <String, dynamic>{
|
||||||
'payload': payloadbytes,
|
'payload': payloadbytes,
|
||||||
'aesKey': aesKey,
|
'aesKey': aesKey,
|
||||||
});
|
});
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
throw DecryptionException(e.message);
|
||||||
|
}
|
||||||
return decryptedPayload;
|
return decryptedPayload;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user