C# AES要解密的数据的长度无效

加密方式  AES-CBC-128

将解密方法改成如下

public  string Decrypt(string toDecrypt, string key)
{
            if (string.IsNullOrEmpty(toDecrypt)) return null;
            Byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);

            System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
            {
                Key = Encoding.UTF8.GetBytes(key),
                IV=Encoding.UTF8.GetBytes(key),
                Mode = System.Security.Cryptography.CipherMode.CBC,
                Padding = System.Security.Cryptography.PaddingMode.PKCS7
            };

            System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor();
            Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            return Encoding.UTF8.GetString(resultArray);
}

 

转载于:https://www.cnblogs.com/siyunianhua/p/8277263.html

你可能感兴趣的:(C# AES要解密的数据的长度无效)