decryptMessage method

String decryptMessage(
  1. String encryptedMessage
)

Decrypts an encrypted message string into the corresponding clear-text string.

encryptedMessage - The encrypted message to decrypt. Returns the decrypted message as a String.

Implementation

String decryptMessage(String encryptedMessage) {
  final Pointer<Utf8> nativeEncryptedMessage =
      encryptedMessage.toNativeUtf8();
  final Pointer<Pointer<Utf8>> result = calloc<Pointer<Utf8>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode = _bindings.SealdEncryptionSession_DecryptMessage(
      _ptr.pointer(), nativeEncryptedMessage, result, err);

  calloc.free(nativeEncryptedMessage);

  if (resultCode != 0) {
    calloc.free(result);
    throw SealdException._fromCPtr(err);
  } else {
    final String decryptedMessage = result.value.toDartString();
    calloc.free(result.value);
    calloc.free(result);
    calloc.free(err);
    return decryptedMessage;
  }
}