C#用使用Des加密后如何在ASP中解密
我通过以下代码对我需要加密的信息加密了,并附加到链接中,进行参数传递。但要是接收方是ASP语言编写的,请问如何在ASP解密由以下函数加密的信息。
已尝试过网络上部分N人的算法,都解密不成功
public static string Encrypt(string Text,string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServ.iceProvider();
byte[] inputByteArray;
inputByteArray=Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms=new System.IO.MemoryStream();
CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret=new StringBuilder();
foreach( byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}",b);
}
return ret.ToString();
}
我通过以下代码对我需要加密的信息加密了,并附加到链接中,进行参数传递。但要是接收方是ASP语言编写的,请问如何在ASP解密由以下函数加密的信息。
已尝试过网络上部分N人的算法,都解密不成功
public static string Encrypt(string Text,string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServ.iceProvider();
byte[] inputByteArray;
inputByteArray=Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms=new System.IO.MemoryStream();
CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret=new StringBuilder();
foreach( byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}",b);
}
return ret.ToString();
}
解决方案 »
- datagridview怎么获得treeview子节点对应数据源的值
- 关于用C#在VS2012上开发游戏平台,请高手指点下技术,我刚开始学C#
- 怎么在代码中设置Lable标签的大小
- 问个巨简单问题,我都不好意思问:)
- C#用WindowMediaPlayer控件制作视频播放器,怎样可以移动和改变它的大小
- C#的部署问题
- 水晶报表的日期时间字段的内容是否不能自动折行,另外导出到excel后格式错乱,请问有无办法解决?
- 谁有C#开发的MIS源代码(结构标准、清晰),请发给我一份,谢谢!
- datagridview的单击事件该怎么写?
- C#中文件操纵类的使用?
- 求助,VS2008和2005编译出的windows应用程序都无法运行!
- xml文件与combobox控件的绑定问题,很急,拜托各位高手了,最好能带上完整地源码
private void button1_Click(object sender, EventArgs e)
{
string _Test = Encrypt("a", "aaa");
this.Text=GetText(_Test,"aaa");
} public static string Encrypt(string Text, string sKey)
{
System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
ms.Position = 0;
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
return ret.ToString();
} public string Decrypt(string p_BytesText, string sKey)
{
string _TempText = p_BytesText;
byte[] _DataBytes = new byte[p_BytesText.Length / 2]; for (int i = 0; i != _DataBytes.Length; i++)
{
_DataBytes[i] = Convert.ToByte(_TempText.Substring(0, 2), 16);
_TempText = _TempText.Remove(0, 2);
} System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider();
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(),System.Security.Cryptography.CryptoStreamMode.Write);
cs.Write(_DataBytes, 0, _DataBytes.Length);
cs.FlushFinalBlock();
byte[] _StringByte = ms.ToArray();
return Encoding.Default.GetString(_StringByte);
}
这是没问题的啊