Add crypto util

This commit is contained in:
Vishnu Mohandas 2020-08-10 02:09:11 +05:30
parent dcce6c5962
commit f80e06762f
3 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,23 @@
import 'dart:convert';
import 'dart:math';
import 'package:encrypt/encrypt.dart';
class CryptoUtil {
static final Random _random = Random.secure();
static String createCryptoRandomString([int length = 32]) {
var values = List<int>.generate(length, (i) => _random.nextInt(256));
return base64Url.encode(values);
}
static String encrypt(String plainText, String key) {
final encrypter = Encrypter(AES(Key.fromUtf8(key)));
return encrypter.encrypt(plainText).base64;
}
static String decrypt(String cipherText, String key) {
final encrypter = Encrypter(AES(Key.fromUtf8(key)));
return encrypter.decrypt(Encrypted.fromBase64(cipherText));
}
}

View file

@ -22,6 +22,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
asn1lib:
dependency: transitive
description:
name: asn1lib
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.5"
async:
dependency: transitive
description:
@ -148,6 +155,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
encrypt:
dependency: "direct main"
description:
name: encrypt
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.2"
esys_flutter_share:
dependency: "direct main"
description:
@ -443,6 +457,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
pointycastle:
dependency: transitive
description:
name: pointycastle
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
process:
dependency: transitive
description:

View file

@ -22,6 +22,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
encrypt: ^4.0.2
cupertino_icons: ^0.1.2
photo_manager: ^0.5.7
provider: ^3.1.0