From ee9490d3a4e3e7423fa90d2ead498fe47363b949 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Wed, 29 Apr 2020 22:27:42 +0200 Subject: [PATCH] Update dart with new pbkdf2 --- example/lib/main.dart | 3 +-- lib/src/native_crypto.dart | 3 ++- lib/symmetric_crypto.dart | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 84ab82e..f8fd5a6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,7 +4,6 @@ import 'dart:developer'; import 'dart:typed_data'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:native_crypto/symmetric_crypto.dart'; import 'package:native_crypto/exceptions.dart'; @@ -53,7 +52,7 @@ class _MyAppState extends State { if (password.isEmpty) { output = 'Password is empty'; } else { - key = await KeyGenerator().pbkdf2(password, 'salt'); + key = await KeyGenerator().pbkdf2(password, 'salt', algorithm: 'sha1'); output = 'Key successfully derived.'; } setState(() { diff --git a/lib/src/native_crypto.dart b/lib/src/native_crypto.dart index f4cd8ed..e78dce1 100644 --- a/lib/src/native_crypto.dart +++ b/lib/src/native_crypto.dart @@ -21,7 +21,7 @@ class NativeCrypto { /// /// [keyLength] is in Bytes. /// It returns an `Uint8List`. - Future pbkdf2(String password, String salt, {int keyLength: 32, int iteration: 10000}) async { + Future pbkdf2(String password, String salt, {int keyLength: 32, int iteration: 10000, String algorithm: 'sha256'}) async { Uint8List key; try { key = await _channel.invokeMethod('pbkdf2', { @@ -29,6 +29,7 @@ class NativeCrypto { 'salt': salt, 'keyLength': keyLength, 'iteration': iteration, + 'algorithm': algorithm, }); } on PlatformException catch (e) { throw e; diff --git a/lib/symmetric_crypto.dart b/lib/symmetric_crypto.dart index 06b654b..fdac852 100644 --- a/lib/symmetric_crypto.dart +++ b/lib/symmetric_crypto.dart @@ -59,10 +59,10 @@ class KeyGenerator { /// /// `keyLength` is in Bytes. /// It returns an `Uint8List`. - Future pbkdf2(String password, String salt, {int keyLength: 32, int iteration: 10000}) async { + Future pbkdf2(String password, String salt, {int keyLength: 32, int iteration: 10000, String algorithm: 'sha256'}) async { Uint8List key; try { - key = await NativeCrypto().pbkdf2( password, salt, keyLength: keyLength, iteration: iteration); + key = await NativeCrypto().pbkdf2( password, salt, keyLength: keyLength, iteration: iteration, algorithm: algorithm); log("PBKDF2 KEY LENGTH: ${key.length}", name: TAG_DEBUG); } on PlatformException catch (e) { log(e.message, name: TAG_ERROR);