embed method

Future<Uint8List> embed({
  1. required Uint8List imageBytes,
  2. required Uint8List data,
  3. required Uint8List key,
  4. required SteganographyMethod method,
  5. SteganographyCipher cipher = SteganographyCipher.aes256Gcm,
})

Implementation

Future<Uint8List> embed({
  required Uint8List imageBytes,
  required Uint8List data,
  required Uint8List key,
  required SteganographyMethod method,
  SteganographyCipher cipher = SteganographyCipher.aes256Gcm,
}) async {
  if (method != SteganographyMethod.telegramRobust2 &&
      !isSupportedCarrierImage(imageBytes)) {
    throw ArgumentError.value(
      imageBytes.length,
      'imageBytes',
      'Not a PNG or JPEG (invalid signature)',
    );
  }
  final encrypted = await SteganographyCrypto.encrypt(
    data,
    keyBytes: key,
    cipher: cipher,
  );
  final payload = switch (method) {
    SteganographyMethod.telegramRobust2 => StegoPayload.packRobust(
        encrypted,
        keyBytes: key,
        repetition: 5,
      ),
    SteganographyMethod.dct => StegoPayload.packRobust(
        encrypted,
        keyBytes: key,
        repetition: 5,
      ),
    SteganographyMethod.dctResidualModulation => StegoPayload.packDrm(
        encrypted,
      ),
    _ => StegoPayload.pack(encrypted),
  };
  try {
    return await _native.embedPng(
      pngBytes: imageBytes,
      payload: payload,
      method: steganographyMethodToInt(method),
    );
  } on PlatformException catch (e) {
    throw _mapPlatform(e);
  }
}