System.Utilities.Cryptography.Encryption.Encrypt256Base64 C# (CSharp) Метод

Encrypt256Base64() публичный статический Метод

Encrypts the specified data using a 256-bit cipher. The key can be any length.
public static Encrypt256Base64 ( Stream Data, byte Key ) : string
Data Stream The data to be encrypted.
Key byte The key used to encrypt the data.
Результат string
        public static string Encrypt256Base64(Stream Data, byte[] Key)
        {
            AesCryptoServiceProvider AES = null;
            var MS = new MemoryStream();
            CryptoStream CS = null;
            BinaryReader DR = null;
            try
            {
                //Get the IV and length corrected Key.
                KeyData KeyData = GenerateKeyIV128(Key);
                //Create the AES crytpograhy object.
                AES = new AesCryptoServiceProvider { BlockSize = 256, KeySize = 256, Key = KeyData.Key, IV = KeyData.IV, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 };
                CS = new CryptoStream(MS, AES.CreateEncryptor(), CryptoStreamMode.Write);

                DR = new BinaryReader(Data);
                var D = new byte[DR.BaseStream.Length];
                DR.Read(D, 0, (int)DR.BaseStream.Length - 1);
                CS.Write(D, 0, D.Length);
                CS.FlushFinalBlock();

                return Convert.ToBase64String(MS.ToArray());
            }
            finally
            {
                if (AES != null) AES.Clear();
                if (CS != null) CS.Dispose();
                MS.Dispose();
                if (DR != null) DR.Close();
            }
        }

Same methods

Encryption::Encrypt256Base64 ( byte Data, byte Key ) : string
Encryption::Encrypt256Base64 ( string Data, byte Key ) : string