-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword.dart
34 lines (30 loc) · 1.17 KB
/
password.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import 'dart:convert';
import 'dart:typed_data';
import 'package:fernet/fernet.dart';
import 'package:pointycastle/key_derivators/api.dart';
import 'package:pointycastle/key_derivators/argon2.dart';
void main() {
const String pwd = 'password';
// Argon2Parameters should be adjusted to be as high as your server
// can tolerate. OWASP provides recommended parameter values at
// https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
final Uint8List key = Uint8List.fromList(utf8.encode(
base64Url.encode(
(Argon2BytesGenerator()
..init(
Argon2Parameters(
Argon2Parameters.ARGON2_id, CryptoUtils.secureRandomBytes(16),
desiredKeyLength: 32,
iterations: 2,
memory: 19 * 1024,
lanes: 1),
))
.process(Uint8List.fromList(utf8.encode(pwd))),
),
));
final Fernet f = Fernet(key);
final Uint8List token = f.encrypt(Uint8List.fromList(
utf8.encode('A really secret message. Not for prying eyes.')));
print(utf8.decode(f.decrypt(token)));
// OUTPUT: 'A really secret message. Not for prying eyes.'
}