我是网络开发新手。我正在我的类(class)项目中制作一个网站,我在其中传输 url 中的数据。我想为用户隐藏该数据,以便他们将来无法更改它。 我正在 ASP.net 上工作。我们将非常感谢您的帮助。
最佳答案
您无法隐藏网址中传输的数据 但你可以加密 url 中的数据 就像我的网址是 text.aspx?Firstname=Robin&LastName=Hood 那么应该显示像 test.aspx?Firstname=121sdnasdkjn121928&LastName=sadklsdn12981029 类似的东西 然后您在获取数据的地方需要解密该数据,它将返回实际数据
这里是加密或解密的函数
public static string Encrypt(string clearText)
{
try
{
string EncryptionKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz1234567890";
byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
clearText = Convert.ToBase64String(ms.ToArray());
}
}
return clearText;
}
catch
{
return null;
}
}
public static string Decrypt(string cipherText)
{
try
{
string EncryptionKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz1234567890";
byte[] cipherBytes = Convert.FromBase64String(cipherText.Replace(" ", "+"));
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
cipherText = Encoding.Unicode.GetString(ms.ToArray());
}
}
return cipherText;
}
catch
{
return null;
}
}
或者
您也可以使用术语 url 路由来隐藏真实的 url 并向用户显示虚假的 url 就像代替 localhost:1544/test.aspx 它将显示 localhost:1544/test 或 localhost:1544/what_ever_you_want 它也会隐藏 .aspx 扩展名
希望这会有所帮助
关于javascript - 隐藏 url 中传输的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44574667/