asp.net c# 中用DES和TripleDES加密成功,但解密失败?请教!
解密时在return语句处报“不正确的数据”请高手指点!//首先导入所需的命名空间usingSystem.Security.Cryptography;usingSyste...
解密时在return语句处报“不正确的数据”请高手指点!
//首先导入所需的命名空间
using System.Security.Cryptography;
using System.Text;
using System.IO;
private static byte[] Key64 = { 42, 16, 93, 156, 78, 4, 218, 32 };
private static byte[] IV64 = { 55, 103, 246, 79, 36, 99, 167, 3 };
public static String Decrypt(String valueString)//DES解密
{
if (valueString != " ")
{
//定义DES的Provider
DESCryptoServiceProvider desprovider = new DESCryptoServiceProvider();
//转换解密的字符串为二进制
byte[] buffer = Convert.FromBase64String(valueString);
//定义内存流
MemoryStream memoryStream = new MemoryStream();
//定义加密流
CryptoStream cryptoStream = new CryptoStream(memoryStream, desprovider.CreateDecryptor(Key64, IV64), CryptoStreamMode.Read);
//定义读IO流
StreamReader readerStream = new StreamReader(cryptoStream);
//返回解密后的字符串
return (readerStream.ReadToEnd());
}
return (null);
} 展开
//首先导入所需的命名空间
using System.Security.Cryptography;
using System.Text;
using System.IO;
private static byte[] Key64 = { 42, 16, 93, 156, 78, 4, 218, 32 };
private static byte[] IV64 = { 55, 103, 246, 79, 36, 99, 167, 3 };
public static String Decrypt(String valueString)//DES解密
{
if (valueString != " ")
{
//定义DES的Provider
DESCryptoServiceProvider desprovider = new DESCryptoServiceProvider();
//转换解密的字符串为二进制
byte[] buffer = Convert.FromBase64String(valueString);
//定义内存流
MemoryStream memoryStream = new MemoryStream();
//定义加密流
CryptoStream cryptoStream = new CryptoStream(memoryStream, desprovider.CreateDecryptor(Key64, IV64), CryptoStreamMode.Read);
//定义读IO流
StreamReader readerStream = new StreamReader(cryptoStream);
//返回解密后的字符串
return (readerStream.ReadToEnd());
}
return (null);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询