Exemple #1
0
        /// <summary>
        /// Decrypts binary data
        /// </summary>
        /// <param name="Data">Binary Data</param>
        /// <param name="Key">Encryption Key</param>
        /// <param name="IV">Initiation Vector</param>
        /// <param name="AssociatedData">Any associated data used for authenticated encryption (AEAD).</param>
        /// <returns>Decrypted Data</returns>
        public override async Task <Stream> Decrypt(Stream Data, byte[] Key, byte[] IV, byte[] AssociatedData)
        {
            TemporaryStream Decrypted = new TemporaryStream();

            try
            {
                Security.ChaChaPoly.ChaCha20 ChaCha20 = new Security.ChaChaPoly.ChaCha20(Key, 1, IV);
                await ChaCha20.EncryptOrDecrypt(Data, Decrypted);

                return(Decrypted);
            }
            catch (Exception ex)
            {
                Decrypted.Dispose();
                ExceptionDispatchInfo.Capture(ex).Throw();
                return(null);
            }
        }
Exemple #2
0
 /// <summary>
 /// Encrypts binary data
 /// </summary>
 /// <param name="Data">Binary Data</param>
 /// <param name="Key">Encryption Key</param>
 /// <param name="IV">Initiation Vector</param>
 /// <param name="AssociatedData">Any associated data used for authenticated encryption (AEAD).</param>
 /// <returns>Encrypted Data</returns>
 public override byte[] Encrypt(byte[] Data, byte[] Key, byte[] IV, byte[] AssociatedData)
 {
     Security.ChaChaPoly.ChaCha20 ChaCha20 = new Security.ChaChaPoly.ChaCha20(Key, 1, IV);
     return(ChaCha20.EncryptOrDecrypt(Data));
 }
Exemple #3
0
 /// <summary>
 /// Encrypts binary data
 /// </summary>
 /// <param name="Data">Data to encrypt.</param>
 /// <param name="Encrypted">Encrypted data will be stored here.</param>
 /// <param name="Key">Encryption Key</param>
 /// <param name="IV">Initiation Vector</param>
 /// <param name="AssociatedData">Any associated data used for authenticated encryption (AEAD).</param>
 public override Task Encrypt(Stream Data, Stream Encrypted, byte[] Key, byte[] IV, byte[] AssociatedData)
 {
     Security.ChaChaPoly.ChaCha20 ChaCha20 = new Security.ChaChaPoly.ChaCha20(Key, 1, IV);
     return(ChaCha20.EncryptOrDecrypt(Data, Encrypted));
 }