Exemplo n.º 1
0
        /// <summary>
        /// Decrypts the provided message using the public key associated with my DID.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The DID specified in the <paramref name="myDid"/> parameter must have been previously created
        /// with a secret key and stored in the wallet specified in the <paramref name="wallet"/> parameter.
        /// </para>
        /// <para>
        /// For further information on storing a DID and its secret key see the
        /// <see cref="CreateAndStoreMyDidAsync(Wallet, string)"/> method.
        /// </para>
        /// </remarks>
        /// <param name="wallet">The wallet containing the DID and associated secret key to use for decryption.</param>
        /// <param name="myDid">The DID to use for decryption.</param>
        /// <param name="did">The DID of the encrypting party to use for verification.</param>
        /// <param name="encryptedMsg">The message to decrypt.</param>
        /// <param name="nonce">The nonce used to encrypt the message.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> that resolves to a byte array containing the decrypted message.</returns>
        public static Task <byte[]> DecryptAsync(Wallet wallet, string myDid, string did, byte[] encryptedMsg, byte[] nonce)
        {
            ParamGuard.NotNull(wallet, "wallet");
            ParamGuard.NotNullOrWhiteSpace(myDid, "myDid");
            ParamGuard.NotNullOrWhiteSpace(did, "did");
            ParamGuard.NotNull(encryptedMsg, "encryptedMsg");
            ParamGuard.NotNull(nonce, "nonce");

            var taskCompletionSource = new TaskCompletionSource <byte[]>();
            var commandHandle        = PendingCommands.Add(taskCompletionSource);

            var commandResult = IndyNativeMethods.indy_decrypt(
                commandHandle,
                wallet.Handle,
                myDid,
                did,
                encryptedMsg,
                encryptedMsg.Length,
                nonce,
                nonce.Length,
                _decryptCallback
                );

            CallbackHelper.CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decrypts the specified messaage.
        /// </summary>
        /// <param name="wallet">The wallet containing the DID to use for decrpytion.</param>
        /// <param name="my_did">My DID.</param>
        /// <param name="did">The DID</param>
        /// <param name="encryptedMsg">The message to decrypt.</param>
        /// <param name="nonce">The nonce.</param>
        /// <returns>An asynchronous task that returns the decrypted message.</returns>
        public static Task <byte[]> DecryptAsync(Wallet wallet, string my_did, string did, byte[] encryptedMsg, byte[] nonce)
        {
            var taskCompletionSource = new TaskCompletionSource <byte[]>();
            var commandHandle        = AddTaskCompletionSource(taskCompletionSource);

            var commandResult = IndyNativeMethods.indy_decrypt(
                commandHandle,
                wallet.Handle,
                my_did,
                did,
                encryptedMsg,
                encryptedMsg.Length,
                nonce,
                nonce.Length,
                _decryptCallback
                );

            CheckResult(commandResult);

            return(taskCompletionSource.Task);
        }