Update platform with algo enums and digest
This commit is contained in:
parent
20d58e1bfd
commit
4d84a938ac
@ -4,8 +4,10 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:native_crypto/src/digest.dart';
|
||||||
|
|
||||||
import 'cipher.dart';
|
import 'cipher.dart';
|
||||||
|
import 'utils.dart';
|
||||||
|
|
||||||
/// Represents a platform, and is usefull to calling
|
/// Represents a platform, and is usefull to calling
|
||||||
/// methods from a specific platform.
|
/// methods from a specific platform.
|
||||||
@ -18,6 +20,22 @@ class Platform {
|
|||||||
return _channel.invokeMethod(method, arguments);
|
return _channel.invokeMethod(method, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Digests a message with a specific algorithm
|
||||||
|
///
|
||||||
|
/// Takes message and algorithm as parameters.
|
||||||
|
///
|
||||||
|
/// Returns a hash as [Uint8List].
|
||||||
|
Future<Uint8List> digest(
|
||||||
|
Uint8List message,
|
||||||
|
HashAlgorithm algorithm,
|
||||||
|
) async {
|
||||||
|
final Uint8List hash = await call('digest', <String, dynamic>{
|
||||||
|
'message': message,
|
||||||
|
'algorithm': algorithm.name,
|
||||||
|
});
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls native PBKDF2.
|
/// Calls native PBKDF2.
|
||||||
///
|
///
|
||||||
/// Takes password and salt as parameters.
|
/// Takes password and salt as parameters.
|
||||||
@ -29,14 +47,14 @@ class Platform {
|
|||||||
String salt, {
|
String salt, {
|
||||||
int keyLength: 32,
|
int keyLength: 32,
|
||||||
int iteration: 10000,
|
int iteration: 10000,
|
||||||
String algorithm: 'sha256',
|
HashAlgorithm algorithm: HashAlgorithm.SHA256,
|
||||||
}) async {
|
}) async {
|
||||||
final Uint8List key = await call('pbkdf2', <String, dynamic>{
|
final Uint8List key = await call('pbkdf2', <String, dynamic>{
|
||||||
'password': password,
|
'password': password,
|
||||||
'salt': salt,
|
'salt': salt,
|
||||||
'keyLength': keyLength,
|
'keyLength': keyLength,
|
||||||
'iteration': iteration,
|
'iteration': iteration,
|
||||||
'algorithm': algorithm,
|
'algorithm': algorithm.name,
|
||||||
});
|
});
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
@ -78,15 +96,15 @@ class Platform {
|
|||||||
Future<List<Uint8List>> encrypt(
|
Future<List<Uint8List>> encrypt(
|
||||||
Uint8List data,
|
Uint8List data,
|
||||||
Uint8List key,
|
Uint8List key,
|
||||||
String algorithm,
|
CipherAlgorithm algorithm,
|
||||||
CipherParameters parameters,
|
CipherParameters parameters,
|
||||||
) async {
|
) async {
|
||||||
final List<Uint8List> payload = await call('encrypt', <String, dynamic>{
|
final List<Uint8List> payload = await call('encrypt', <String, dynamic>{
|
||||||
'data': data,
|
'data': data,
|
||||||
'key': key,
|
'key': key,
|
||||||
'algorithm': algorithm,
|
'algorithm': algorithm.name,
|
||||||
'mode': parameters.mode.index,
|
'mode': parameters.mode.name,
|
||||||
'padding': parameters.padding.index,
|
'padding': parameters.padding.name,
|
||||||
});
|
});
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
@ -98,16 +116,16 @@ class Platform {
|
|||||||
Future<Uint8List> decrypt(
|
Future<Uint8List> decrypt(
|
||||||
List<Uint8List> payload,
|
List<Uint8List> payload,
|
||||||
Uint8List key,
|
Uint8List key,
|
||||||
String algorithm,
|
CipherAlgorithm algorithm,
|
||||||
CipherParameters parameters,
|
CipherParameters parameters,
|
||||||
) async {
|
) async {
|
||||||
final Uint8List data =
|
final Uint8List data =
|
||||||
await _channel.invokeMethod('decrypt', <String, dynamic>{
|
await _channel.invokeMethod('decrypt', <String, dynamic>{
|
||||||
'payload': payload,
|
'payload': payload,
|
||||||
'key': key,
|
'key': key,
|
||||||
'algorithm': algorithm,
|
'algorithm': algorithm.name,
|
||||||
'mode': parameters.mode.index,
|
'mode': parameters.mode.name,
|
||||||
'padding': parameters.padding.index,
|
'padding': parameters.padding.name,
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user