KeyStore.createNew constructor

KeyStore.createNew(
  1. String credentials,
  2. String password,
  3. Random random, {
  4. int scryptN = 262144,
  5. int p = 1,
})

Creates a new key store wrapping the specified credentials by encrypting the private key with the password. The random instance, which should be cryptographically secure, is used to generate encryption keys. You can configure the parameter N of the scrypt algorithm if you need to. The default value for scryptN is 8192. Be aware that this N must be a power of two.

Implementation

factory KeyStore.createNew(String credentials, String password, Random random,
    {int scryptN = 262144, int p = 1}) {
  final passwordBytes =
      Uint8List.fromList(str2ByteArray(password, enc: 'latin1'));
  final dartRandom = RandomBridge(random);
  final salt = dartRandom.nextBytes(32);
  final derivator = _ScryptKeyDerivator(
      defaultOptions['kdfParams']['dkLen'] as int,
      scryptN,
      defaultOptions['kdfParams']['r'] as int,
      p,
      salt);
  final uuid = generateUuidV4();
  final iv = dartRandom.nextBytes(128 ~/ 8);
  return KeyStore._(credentials, derivator, passwordBytes, iv, uuid);
}