我有两页两页。 MainPage.aspx和DealerPage.aspx
我从MainPage向DealerPage发送请求QueryString,但我想在传递给DealerPage时加密QueryString
在MainPage.aspx(Javascript)
google.maps.event.addListener(marker2, "click", function (e) {
infoWindow2.setContent(data2.description);
infoWindow2.open(map2, marker2);
window.location = "DealerPage.aspx?DI=" + data2.plate;
icon: InitIcon
});
E.g
http:localhost/DealerPage.aspx?DI=485180610
在DealerPage.aspx.cs中,我得到并使用QueryString。
private string tankerPlate = "";
protected void Page_Load(object sender, EventArgs e)
{
this.truckPlate = this.Page.Request.QueryString["DI"];
}
我不希望显示像DI = 485180610。
我希望DI =加密并解密以使用下一页。
答案 0 :(得分:1)
试试这个
public static class Crypt
{
// Must be random
private static readonly byte[] key = new byte[24] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4 };
public static string Encrypt(string input)
{
byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input);
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
tripleDES.GenerateKey();
tripleDES.Key = key;
tripleDES.Mode = CipherMode.ECB;
tripleDES.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tripleDES.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
tripleDES.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
public static string Decrypt(string input)
{
byte[] inputArray = Convert.FromBase64String(input);
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
tripleDES.Key = key;
tripleDES.Mode = CipherMode.ECB;
tripleDES.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tripleDES.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
tripleDES.Clear();
return UTF8Encoding.UTF8.GetString(resultArray);
}
}