您的问题似乎不完整,您是想询问关于C语言编程的某个具体问题吗?比如C语言的语法、编程技巧、项目开发等。请提供更具体的信息,这样我才能给出更准确的回答。
- 内容介绍
- 文章标签
- 相关推荐
本文共计382个文字,预计阅读时间需要2分钟。
属性设置在加密解密时出现不一致,导致填充无效,无法被移除的错误。这是其中的一个原因。
csharprDel.Key=resultArray;rDel.BlockSize=128;rDel.Mode=CipherMode.ECB;rDel.Padding=PaddingMode.Zeros;
属性设置在加密解密时不一致出现“填充无效,无法被移除”的错误。但是这只是其中的一个原因。
rDel.Key = resultArray;
rDel.BlockSize = 128;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.Zeros;
加解密属性名一致还是报错
交初始key的位置互换正常。具体是初始化属性有先后顺序
代码如下:
public static string AesEncrypt(string str, string key)
{
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
System.Security.Cryptography.RijndaelManaged rm = new
System.Security.Cryptography.RijndaelManaged
{
BlockSize =128,
KeySize=256,
Key = Encoding.UTF8.GetBytes(key),
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7,
};
System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
public static string AesDecrypt(string str, string key)
{
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Convert.FromBase64String(str);
System.Security.Cryptography.RijndaelManaged rm = new
System.Security.Cryptography.RijndaelManaged
{
BlockSize = 128,
KeySize = 256,
Key = Encoding.UTF8.GetBytes(key),
Mode = System.Security.Cryptography.CipherMode.ECB,
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);
}
本文共计382个文字,预计阅读时间需要2分钟。
属性设置在加密解密时出现不一致,导致填充无效,无法被移除的错误。这是其中的一个原因。
csharprDel.Key=resultArray;rDel.BlockSize=128;rDel.Mode=CipherMode.ECB;rDel.Padding=PaddingMode.Zeros;
属性设置在加密解密时不一致出现“填充无效,无法被移除”的错误。但是这只是其中的一个原因。
rDel.Key = resultArray;
rDel.BlockSize = 128;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.Zeros;
加解密属性名一致还是报错
交初始key的位置互换正常。具体是初始化属性有先后顺序
代码如下:
public static string AesEncrypt(string str, string key)
{
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
System.Security.Cryptography.RijndaelManaged rm = new
System.Security.Cryptography.RijndaelManaged
{
BlockSize =128,
KeySize=256,
Key = Encoding.UTF8.GetBytes(key),
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7,
};
System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
public static string AesDecrypt(string str, string key)
{
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Convert.FromBase64String(str);
System.Security.Cryptography.RijndaelManaged rm = new
System.Security.Cryptography.RijndaelManaged
{
BlockSize = 128,
KeySize = 256,
Key = Encoding.UTF8.GetBytes(key),
Mode = System.Security.Cryptography.CipherMode.ECB,
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);
}

