Exemple #1
0
        /// <summary>
        /// Encrypt a chunk of data
        ///
        /// As per best practise creates a new IV for every record encryted, this IV is exported in the output along with
        /// the encrypted data
        /// </summary>
        /// <param name="data">Data that will be encrypted</param>
        /// <returns>Encrypted data, first chunks will contain length of IV (4 bytes), then the IV bytes</returns>
        public byte[] Encrypt(byte[] data)
        {
            using (var ms = new MemoryStream())
            {
                using (var aes = new AESEncryptStream(_key, ms, false))
                {
                    aes.Write(data, 0, data.Length);
                }

                return(ms.ToArray());
            }
        }
        /// <summary>
        /// Encrypt a chunk of data
        /// 
        /// As per best practise creates a new IV for every record encryted, this IV is exported in the output along with
        /// the encrypted data
        /// </summary>
        /// <param name="data">Data that will be encrypted</param>
        /// <returns>Encrypted data, first chunks will contain length of IV (4 bytes), then the IV bytes</returns>
        public byte[] Encrypt(byte[] data)
        {
            using (var ms = new MemoryStream())
            {
                using (var aes = new AESEncryptStream(_key, ms, false))
                {
                    aes.Write(data, 0, data.Length);
                }

                return ms.ToArray();
            }
        }