useCryptography method

dynamic useCryptography(
  1. dynamic key
)

Implementation

useCryptography(key) async {
  var textData = "THIS STRING FOR ENCRYPT";

  // try encrypt
  final algorithm = cry.AesGcm.with256bits();

  // Generate a random 256-bit secret key
  final secretKey = await algorithm.newSecretKeyFromBytes(key);

  // Generate a random 96-bit nonce.
  final nonce = algorithm.newNonce();

  // Encrypt
  final clearText = [1, 2, 3];
  final secretBox = await algorithm.encrypt(
    clearText,
    secretKey: secretKey,
    nonce: nonce,
  );
  // print('Ciphertext: ${secretBox.cipherText}');
  // print('MAC: ${secretBox.mac}');
  // print(secretBox.concatenation());

  //Decrypt
  final secretDec = await algorithm.decrypt(secretBox, secretKey: secretKey);
  // print(secretDec);
}