secrets property
Retrieves the secrets from a potentially secure place.
Implementation
@override
Future<AuthenticationSecretsModel> get secrets async {
final file = File(secretsFile);
if (file.existsSync()) {
final map = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
final model = AuthenticationSecretsModel()..loadFromMap(map);
return model;
}
file.createSync(recursive: true);
final myRandom = random ?? Random.secure();
final hasher = PasswordHasher(pepper: '', random: myRandom);
final ivBase64 = IV(
Uint8List.fromList(
List.generate(16, (i) => myRandom.nextInt(256)),
),
).base64;
final saltBase64 = IV(
Uint8List.fromList(
List.generate(32, (i) => myRandom.nextInt(256)),
),
).base64;
final newModel = AuthenticationSecretsModel()
..methodMinHashes = myRandom.nextInt(200) + 100
..methodMaxHashes = myRandom.nextInt(200) + 600
..pepper = hasher.generateSalt(length: myRandom.nextInt(32) + 64)
..methodIv64 = ivBase64
..methodSalt64 = saltBase64;
file.writeAsStringSync(json.encode(newModel.toMap()));
return newModel;
}