Add digest enum
This commit is contained in:
parent
4f5b6bf351
commit
8a112648bf
@ -52,7 +52,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
if (password.isEmpty) {
|
if (password.isEmpty) {
|
||||||
output = 'Password is empty';
|
output = 'Password is empty';
|
||||||
} else {
|
} else {
|
||||||
key = await KeyGenerator().pbkdf2(password, 'salt', algorithm: 'sha1');
|
key = await KeyGenerator().pbkdf2(password, 'salt', digest: Digest.sha1);
|
||||||
output = 'Key successfully derived.';
|
output = 'Key successfully derived.';
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -15,6 +15,9 @@ const String TAG_DEBUG = 'debug.native_crypto.symmetric_crypto';
|
|||||||
/// Defines all available key sizes.
|
/// Defines all available key sizes.
|
||||||
enum KeySize { bits128, bits192, bits256 }
|
enum KeySize { bits128, bits192, bits256 }
|
||||||
|
|
||||||
|
/// Defines all available digest.
|
||||||
|
enum Digest { sha1, sha256 }
|
||||||
|
|
||||||
/// Defines all available ciphers.
|
/// Defines all available ciphers.
|
||||||
enum Cipher { AES }
|
enum Cipher { AES }
|
||||||
|
|
||||||
@ -59,11 +62,17 @@ class KeyGenerator {
|
|||||||
///
|
///
|
||||||
/// `keyLength` is in Bytes.
|
/// `keyLength` is in Bytes.
|
||||||
/// It returns an `Uint8List`.
|
/// It returns an `Uint8List`.
|
||||||
Future<Uint8List> pbkdf2(String password, String salt, {int keyLength: 32, int iteration: 10000, String algorithm: 'sha256'}) async {
|
Future<Uint8List> pbkdf2(String password, String salt, {int keyLength: 32, int iteration: 10000, Digest digest: Digest.sha256}) async {
|
||||||
Uint8List key;
|
Uint8List key;
|
||||||
|
|
||||||
|
String algo;
|
||||||
|
if (digest == Digest.sha1) algo = 'sha1';
|
||||||
|
if (digest == Digest.sha256) algo = 'sha256';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
key = await NativeCrypto().pbkdf2( password, salt, keyLength: keyLength, iteration: iteration, algorithm: algorithm);
|
key = await NativeCrypto().pbkdf2( password, salt, keyLength: keyLength, iteration: iteration, algorithm: algo);
|
||||||
log("PBKDF2 KEY LENGTH: ${key.length}", name: TAG_DEBUG);
|
log(key.toString());
|
||||||
|
log("PBKDF2 KEY LENGTH: ${key.length} | DIGEST: $algo", name: TAG_DEBUG);
|
||||||
} on PlatformException catch (e) {
|
} on PlatformException catch (e) {
|
||||||
log(e.message, name: TAG_ERROR);
|
log(e.message, name: TAG_ERROR);
|
||||||
throw e;
|
throw e;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user