asp.net中锚定标记查询字符串的加密和解密
我读了很多关于如何加密和解密查询字符串的文章,但似乎找不到任何关于如何在html标记中使用它的文章。这就是我想要达到的目标 产品id是一个整数,但我不想像那样将其发送到SingleProduct.aspx页面。我想对它进行加密,然后在页面上对其进行解密,以使其用于其他操作asp.net中锚定标记查询字符串的加密和解密,asp.net,query-string,Asp.net,Query String,我读了很多关于如何加密和解密查询字符串的文章,但似乎找不到任何关于如何在html标记中使用它的文章。这就是我想要达到的目标 产品id是一个整数,但我不想像那样将其发送到SingleProduct.aspx页面。我想对它进行加密,然后在页面上对其进行解密,以使其用于其他操作 <a href="Singleproduct.aspx?Product=<%#Eval("Product_Id")) %>"> 我使用用户id会话[UserId]作为加密密钥。裁判 productli
<a href="Singleproduct.aspx?Product=<%#Eval("Product_Id")) %>">
我使用用户id会话[UserId]作为加密密钥。裁判 productlist.aspx类 Singleproduct.aspx.cs按会话[UserId]解密
或者,您可以为链接到详细信息id添加GUID字段。查看Mad Kristensen关于查询字符串加密的HttpModule的文章。感谢您的回复。我不能在我的锚html标记中使用它吗?在获取产品数据后加密id如何?
<a href="Singleproduct.aspx?enProduct=<%#EncodeId(Eval("id")) %>">En Product Detail</a>
protected void Page_Load(object sender, EventArgs e)
{
Session["UserId"] = "rainmaker";
}
protected string EncodeId(object id)
{
var encryptKey = (string)Session["UserId"];
var encryptKeyArray = Encoding.ASCII.GetBytes(encryptKey);
Array.Resize(ref encryptKeyArray, 16);
// Encrypt the string to an array of bytes.
byte[] encrypted = EncryptStringToBytes(Convert.ToString(id), encryptKeyArray, encryptKeyArray);
string encryptedStr = Convert.ToBase64String(encrypted).Replace('+', '-').Replace('/', '_');
return encryptedStr;
}
var enProductId = Request.QueryString["enProduct"];
if (enProductId != null)
{
var encryptKey = (string)Session["UserId"];
var encryptKeyArray = Encoding.ASCII.GetBytes(encryptKey);
Array.Resize(ref encryptKeyArray, 16);
var encryptedArray = Convert.FromBase64String(enProductId.Replace('_', '/').Replace('-', '+'));
// Decrypt the bytes to a string.
string id = DecryptStringFromBytes(encryptedArray, encryptKeyArray, encryptKeyArray);
Response.Write(id);
}