예제 #1
0
        /// <summary>
        /// Decrypt the encrypted contents of a byte array
        /// </summary>
        /// <param name="cipher">The <see cref="ICipher"/> to use for decrypting the data</param>
        /// <param name="input">The encrypted data to decrypt</param>
        /// <returns>An array containing the cleartext data</returns>
        public static async Task <byte[]> DecryptAsync(this ICipher cipher, byte[] input)
        {
            using (var istream = new MemoryStream(input))
                using (var ostream = new MemoryStream()) {
                    await cipher.DecryptAsync(istream, ostream).ConfigureAwait(false);

                    return(ostream.ToArray());
                }
        }
예제 #2
0
 /// <summary>
 /// Decrypt the encrypted contents of a byte array and writes it to an output stream
 /// </summary>
 /// <param name="cipher">The <see cref="ICipher"/> to use for decrypting the data</param>
 /// <param name="input">The encrypted data to decrypt</param>
 /// <param name="output">The stream to write the cleartext data to</param>
 /// <remarks>This method leave the <paramref name="output"/> stream open</remarks>
 public static async Task DecryptAsync(this ICipher cipher, byte[] input, Stream output)
 {
     using (var istream = new MemoryStream(input))
         await cipher.DecryptAsync(istream, output).ConfigureAwait(false);
 }