C#DESC解密问题
我在网上找了个实例,实际运行测试了下,可运行到byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length);时老是报CryptographicException异常,请哪位高手指点下哪里有错,还是参数错误。
public string DecryptString(string inputInfo, string sKey)
{
string[] sInput = inputInfo.Split("-".ToCharArray());
byte[] data = new byte[sInput.Length];
for (int i = 0; i < sInput.Length; i++)
{
data[i] = byte.Parse(sInput[i], NumberStyles.HexNumber);
}
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
ICryptoTransform desencrypt = DES.CreateDecryptor();
byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length);
return Encoding.UTF8.GetString(result);
}
------解决方案-------------------- /// <summary>
/// DES对称加密方法
/// </summary>
/// <param name="InitData">原始待加密数据</param>
/// <param name="SecretKey">加密密钥,密钥长度必须为八位有效英文字符</param>
public static string EncryptData(object InitData, string SecretKey)