encrypt static method

Uint8List encrypt(
  1. Uint8List value,
  2. PublicKey publicKey
)

Encrypts the given value using the given public key.

Implementation

static Uint8List encrypt(Uint8List value, PublicKey publicKey) {
  ECDHResult enc = ECDHCrypt.encrypt(value, publicKey: publicKey);

  String mac = PDUtil.byteToHex(PDUtil.hmacMd5(enc.data, enc.key));

  int originalDataLength = value.length;
  int originalDataLengthIncPadLength =
      (originalDataLength % 16) == 0 ? 0 : 16 - (originalDataLength % 16);

  EciesData keyData = EciesData(
      publicKey: enc.publicKey,
      mac: PDUtil.hexToBytes(mac),
      encryptedData: enc.data,
      originalDataLength: originalDataLength,
      originalDataLengthIncPadding: originalDataLengthIncPadLength);
  return EciesCoding.encodeToBytes(keyData);
}