encrypt static method

String encrypt({
  1. String? secretkey = _sharedkey,
  2. String? vector = _sharedkey,
  3. String? text,
})

Implementation

static String encrypt({String? secretkey = _sharedkey, String? vector = _sharedkey, String? text})
{
  if (S.isNullOrEmpty(text)) return "";

  Uint8List plainText = Uint8List.fromList(utf8.encode(text!));
  Uint8List key       = Uint8List.fromList(utf8.encode(secretkey!));
  Uint8List iv        = Uint8List.fromList(utf8.encode(vector!));

  PaddedBlockCipher cipher = PaddedBlockCipherImpl(PKCS7Padding(), CBCBlockCipher(AESEngine()));
  cipher.init(true, PaddedBlockCipherParameters<CipherParameters, CipherParameters>(ParametersWithIV<KeyParameter>(KeyParameter(key), iv), null));
  Uint8List cipherText = cipher.process(plainText);

  Base64Encoder encoder = Base64Encoder.urlSafe();
  return encoder.convert(cipherText);
}