/// <summary> /// Encrypts the provided message with the public key of the specified DID using the anonymous-encryption scheme. /// </summary> /// <remarks> /// <para>If the wallet specified in the <paramref name="wallet"/> parameter contains the public key /// associated with the DID specified in the <paramref name="did"/> parameter and the value has /// not expired then this key will be used for encryption. /// </para> /// <para>On the other hand, if the public key is not present in the wallet or has expired the public /// key will be read from the ledger in the node pool specified in the <paramref name="pool"/> /// parameter and the wallet will be updated with the new public key if required. /// </para> /// <para>For further information on registering a public key for a DID see the /// <see cref="StoreTheirDidAsync(Wallet, string)"/>method and for information on the expiry of /// values in a wallet see the <see cref="Wallet.CreateWalletAsync(string, string, string, string, string)"/> /// and <see cref="Wallet.OpenWalletAsync(string, string, string)"/> methods. /// </para> /// </remarks> /// <param name="wallet">The wallet containing the DID to use for encryption.</param> /// <param name="pool">The node pool to read the public key from if required.</param> /// <param name="did">The DID the message is to be encrypted for.</param> /// <param name="msg">The message to encrypt.</param> /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a byte array containing the encrypted message once encryption is complete.</returns> public static Task <byte[]> EncryptSealedAsync(Wallet wallet, Pool pool, string did, byte[] msg) { var taskCompletionSource = new TaskCompletionSource <byte[]>(); var commandHandle = PendingCommands.Add(taskCompletionSource); var commandResult = IndyNativeMethods.indy_encrypt_sealed( commandHandle, wallet.Handle, pool.Handle, did, msg, msg.Length, _encryptSealedCallback); CallbackHelper.CheckResult(commandResult); return(taskCompletionSource.Task); }