Example #1
0
        /// <summary>
        /// Decrypts the aes.
        /// </summary>
        /// <param name="bytesToDecrypt">The bytes to decrypt.</param>
        /// <returns></returns>
        public byte[] DecryptAes(byte[] bytesToDecrypt)
        {
            try
            {
                bytesToDecrypt.CheckNullOrEmptyCollection(nameof(bytesToDecrypt));

                using (MemoryStream msDecrypt = new MemoryStream(bytesToDecrypt))
                {
                    using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, _rijAlg.CreateDecryptor(_aesKeys.Key, _aesKeys.InitializationVector), CryptoStreamMode.Read))
                    {
                        //csDecrypt.Write(bytesToDecrypt, 0, bytesToDecrypt.Length);
                        //csDecrypt.FlushFinalBlock();
                        //return msDecrypt.ToArray();

                        return(csDecrypt.ReadStreamToBytes());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle(new { bytesToDecrypt });
            }
        }