页面传值的加密解密
<a href="../job/news.aspx?id=<%#DataBinder.Eval(Container.DataItem, "id")%>" target="_blank">我想对id 进行MD5加密,到news.aspx页面解密,怎么做啊?各位帮帮忙啊! --------------------编程问答-------------------- 对字符串string1加密:
string str1=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(string1,"SHA1")
或者System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(string,"md5")
到news.aspx页面解密,可以对string2再加密得到str2,然后比较str1==str2 --------------------编程问答-------------------- 如果想正向解密的话,使用des --------------------编程问答-------------------- 用这个吧
在引用using System.Security.Cryptography;
const string KEY_64 = "VavicApp";//注意了,是8个字符,64位
const string IV_64 = "VavicApp";
public string Encode(string data)
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
int i = cryptoProvider.KeySize;
MemoryStream ms = new MemoryStream();
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey,byIV), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cst);
sw.Write(data);
sw.Flush();
cst.FlushFinalBlock();
sw.Flush();
return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
}
public string Decode(string data)//解密
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
byte[] byEnc;
try
{
byEnc = Convert.FromBase64String(data);
}
catch
{
return null;
}
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream(byEnc);
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey,byIV), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cst);
return sr.ReadToEnd();
} --------------------编程问答-------------------- <a href="../job/news.aspx?id= <%#DataBinder.Eval(Container.DataItem, "id")%>" target="_blank">
id= <%#DataBinder.Eval(Container.DataItem, "id")%>
改为:DataBinder.Eval(Container.DataItem, "id")
id= <%# System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(DataBinder.Eval(Container.DataItem, "id").ToString(),"md5") %>" --------------------编程问答-------------------- 不要考虑用MD5加密,MD5是不可逆的,也就是不能解密
用别的加密方法,比如DES
参考一下:
http://blog.csdn.net/jjhua/archive/2007/10/28/1850469.aspx --------------------编程问答-------------------- MD5不可逆
补充:.NET技术 , ASP.NET