/// <summary> /// Encrypts the provided message with the public key of the specified DID. /// </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="myDid">The DID used to encrypt the message.</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 an <see cref="EncryptResult"/> once encryption is complete.</returns> public static Task <EncryptResult> EncryptAsync(Wallet wallet, Pool pool, string myDid, string did, byte[] msg) { ParamGuard.NotNull(wallet, "wallet"); ParamGuard.NotNull(pool, "pool"); ParamGuard.NotNullOrWhiteSpace(myDid, "myDid"); ParamGuard.NotNullOrWhiteSpace(did, "did"); ParamGuard.NotNull(msg, "msg"); var taskCompletionSource = new TaskCompletionSource <EncryptResult>(); var commandHandle = PendingCommands.Add(taskCompletionSource); var commandResult = IndyNativeMethods.indy_encrypt( commandHandle, wallet.Handle, pool.Handle, myDid, did, msg, msg.Length, _encryptCallback); CallbackHelper.CheckResult(commandResult); return(taskCompletionSource.Task); }
/// <summary> /// Encrypts the specified message for the specified DID. /// </summary> /// <param name="wallet">The wallet containing the DID to use for encyption.</param> /// <param name="pool">The pool</param> /// <param name="my_did">My DID</param> /// <param name="did">The did to encrypt for.</param> /// <param name="msg">The message to encrypt.</param> /// <returns>An asynchronous task that returns an EncryptResult.</returns> public static Task <EncryptResult> EncryptAsync(Wallet wallet, Pool pool, string my_did, string did, byte[] msg) { var taskCompletionSource = new TaskCompletionSource <EncryptResult>(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); var commandResult = IndyNativeMethods.indy_encrypt( commandHandle, wallet.Handle, pool.Handle, my_did, did, msg, msg.Length, _encryptCallback); CheckResult(commandResult); return(taskCompletionSource.Task); }