encryptMessage method

String encryptMessage(
  1. String clearMessage
)

Encrypts a clear-text string into an encrypted message, for the recipients of this session.

clearMessage - The message to encrypt. Returns the encrypted message as a String.

Implementation

String encryptMessage(String clearMessage) {
  final Pointer<Utf8> nativeClearMessage = clearMessage.toNativeUtf8();
  final Pointer<Pointer<Utf8>> result = calloc<Pointer<Utf8>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode = _bindings.SealdEncryptionSession_EncryptMessage(
      _ptr.pointer(), nativeClearMessage, result, err);

  calloc.free(nativeClearMessage);

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