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

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

Encrypts the specified data using a 256-bit cipher. The key can be any length.
public static Encrypt256ByteSecure ( System Data, byte Key ) : byte[]
Data System The data to be encrypted. Must be UTF8.
Key byte The key used to encrypt the data.
Результат byte[]
        public static byte[] Encrypt256ByteSecure(System.Security.SecureString Data, byte[] Key)
        {
            AesCryptoServiceProvider AES = null;
            var MS = new MemoryStream();
            CryptoStream CS = 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);

                byte[] D = System.Text.Encoding.UTF8.GetBytes(ConvertToUnsecureString(Data));
                CS.Write(D, 0, D.Length);
                CS.FlushFinalBlock();

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