encrypt static method

Uint8List encrypt(
  1. PrivateKey privateKey,
  2. String password
)

Encrypts a private key

Implementation

static Uint8List encrypt(PrivateKey privateKey, String password) {
  Uint8List privateKeyEncoded = PrivateKeyCoder().encodeToBytes(privateKey);

  Random randomGenerator = Random.secure();
  Uint8List salt = Uint8List(8);
  for (int i = 0; i < 8; i++) {
    salt[i] = randomGenerator.nextInt(255);
  }

  KeyIV keyInfo = KDF.pascalCoin(password, salt: salt);

  Uint8List privateKeyEncrypted = AesCbcPkcs7.encrypt(privateKeyEncoded,
      key: keyInfo.key, iv: keyInfo.iv);

  return PDUtil.concat(
      [PDUtil.stringToBytesUtf8("Salted__"), salt, privateKeyEncrypted]);
}