Add crypto util
This commit is contained in:
parent
dcce6c5962
commit
f80e06762f
3 changed files with 45 additions and 0 deletions
23
lib/utils/crypto_util.dart
Normal file
23
lib/utils/crypto_util.dart
Normal 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));
|
||||
}
|
||||
}
|
21
pubspec.lock
21
pubspec.lock
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue