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

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