示例#1
0
        public static byte[] EncryptOrDecryptData(bool encrypt, byte[] data, int start, int length)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            ICryptoTransform cryptoTransform = (encrypt ? EncryptionAlgorithm.CreateEncryptor() :
                                                EncryptionAlgorithm.CreateDecryptor());
            MemoryStream stream = new MemoryStream();

            using (CryptoStream cryptoStream = new CryptoStream(stream, cryptoTransform, CryptoStreamMode.Write))
            {
                cryptoStream.Write(data, start, length);
                cryptoStream.FlushFinalBlock();

                return(stream.ToArray());
            }
        }
 private void InitializeDecryptor(byte[] key, byte[] initializationVector)
 {
     Decryptor = EncryptionAlgorithm.CreateDecryptor(key, initializationVector);
 }