Add generatePassword; refactor GestureDetectors to CupertinoButton;

refactor hidden classes fields; refactor repositories to one library
This commit is contained in:
mitchell 2019-07-17 22:20:04 -04:00
parent 67744527cc
commit 5a42345c08
11 changed files with 293 additions and 204 deletions

View file

@ -56,11 +56,13 @@ String encrypt(String plainText, String masterpass, [String privateKey]) {
);
final random = Random.secure();
final ivBytes = List<int>.generate(aesBlockSize, (_) => random.nextInt(byteIntMax));
final ivBytes =
List<int>.generate(aesBlockSize, (_) => random.nextInt(byteIntMax));
final iv = IV(Uint8List.fromList(ivBytes));
final encrypter = Encrypter(AES(Key(key), mode: AESMode.cbc));
final cipherBytes = List<int>.from(encrypter.encrypt(plainText, iv: iv).bytes);
final cipherBytes =
List<int>.from(encrypter.encrypt(plainText, iv: iv).bytes);
cipherBytes.insertAll(0, ivBytes);
if (privateKeyWasEmpty) {
@ -72,6 +74,30 @@ String encrypt(String plainText, String masterpass, [String privateKey]) {
return base64.encode(cipherBytes);
}
String generatePassword(int length,
[bool numbers = true, bool specials = true]) {
const alphaValues = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numberValues = '1234567890';
const specialValues = '!@#\$%^&*()-_=+';
final random = Random.secure();
List<int> values;
if (numbers && specials) {
values = (alphaValues + numberValues + specialValues).codeUnits;
} else if (numbers) {
values = (alphaValues + numberValues).codeUnits;
} else if (specials) {
values = (alphaValues + specialValues).codeUnits;
}
final valuesLen = values.length;
final passValues =
List<int>.generate(length, (_) => values[random.nextInt(valuesLen)]);
return String.fromCharCodes(passValues);
}
const saltSize = 16;
const pbkdf2Rounds = 4096;
const keySize = 32;