首页 > 代码库 > AES 加密位: 128位,加密模式:CBC, 填充模式:Zeros

AES 加密位: 128位,加密模式:CBC, 填充模式:Zeros

// AES 加密
        public byte[] AESEncrypt(string text)
        {
            byte[] data = http://www.mamicode.com/Encoding.Unicode.GetBytes(text);>
// AES 解密
        public string AESDecrypt(byte[] data)
        {
            SymmetricAlgorithm aes = Rijndael.Create();
            aes.Key = keyArray;
            aes.IV = keyArray;
            aes.Mode = CipherMode.CBC;
            aes.Padding = PaddingMode.Zeros;
            byte[] decryptBytes = new byte[data.Length];

            using (MemoryStream ms = new MemoryStream(data))
            {
                using (CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Read))
                {
                    cs.Read(decryptBytes, 0, decryptBytes.Length);
                    cs.Close();
                    ms.Close();
                }
            }
            aes.Clear();

            return System.Text.Encoding.Unicode.GetString(decryptBytes).Replace("\0", " ");
        }

AES 加密位: 128位,加密模式:CBC, 填充模式:Zeros