encrypt static method

String encrypt(
  1. String value
)

Encrypt any data

Implementation

static String encrypt(String value) {
  final key = _generateKey(host, clientId);
  final iv = _generateIv();
  Uint8List msgByte = Uint8List.fromList(utf8.encode(value));
  var b = BytesBuilder();
  b.add(msgByte);
  int minLength = 16 - msgByte.lengthInBytes % 16;
  b.add(Uint8List(16 + minLength));
  Uint8List cipherText = _processBlocks(
    encrypt: true,
    params: castle.ParametersWithIV(castle.KeyParameter(key), iv),
    input: b.toBytes(),
  );
  var c2 = BytesBuilder();
  c2.add(iv);
  c2.add(cipherText);
  Uint8List finalText = c2.toBytes();
  return base64.encode(finalText);
}