encrypt static method

String encrypt(
  1. String password,
  2. String plainText
)

Encrypts plain text by using the specified password.

Implementation

static String encrypt(String password, String plainText) {
  final encryptionSalt = generateSalt();
  final hmacSalt = generateSalt();
  final iv = _generateIv(RNCryptorSettings.ivLength);

  final encryptionKey = generateKey(password, encryptionSalt);
  final hmacKey = generateKey(password, hmacSalt);
  final cipherText = _encryptCore(encryptionKey, iv, plainText)!;

  var data = BytesBuilder();
  data.add([RNCryptorSettings.version]);
  data.add([1]);
  data.add(encryptionSalt);
  data.add(hmacSalt);
  data.add(iv);
  data.add(cipherText);

  final hmac = _generateHmac(data.toBytes(), hmacKey);
  data.add(hmac);

  return base64.encode(data.toBytes());
}