encrypt static method

Future<WCEncryptionPayload> encrypt(
  1. String data,
  2. String key
)

Implementation

static Future<WCEncryptionPayload> encrypt(String data, String key) async {
  final _keyBytes = hexToBytes(key);
  final algorithm = AesCbc.with256bits(macAlgorithm: MacAlgorithm.empty);
  final secretKey = SecretKey(_keyBytes);
  final secretBox = await algorithm.encrypt(
    utf8.encode(data),
    secretKey: secretKey,
  );
  final computedHmac =
      await _computeHmac(secretBox.cipherText, secretBox.nonce, _keyBytes);
  final encryptedData = bytesToHex(secretBox.cipherText);
  return WCEncryptionPayload(
    data: encryptedData,
    hmac: bytesToHex(computedHmac.bytes),
    iv: bytesToHex(secretBox.nonce),
  );
}