Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ASP.NET网站中加密查询字符串参数?_Asp.net_Encryption_Query String - Fatal编程技术网

如何在ASP.NET网站中加密查询字符串参数?

如何在ASP.NET网站中加密查询字符串参数?,asp.net,encryption,query-string,Asp.net,Encryption,Query String,在我的一个ASP.Net网站中,我必须提供一个指向用户的链接,其中所有查询字符串参数都应加密 我的想法是使用命令“aspnet\u regiis”(用于加密web.config数据),将输出作为已发布url中的查询字符串传递 当用户单击该链接时,我首先解密字符串,然后获取查询字符串的原始数据 我这样做对吗?有什么好的技术可以加密和解密查询字符串吗?在ASP.NET上下文中加密和解密字符串的好方法是使用 它似乎只适用于cookie,但在其他上下文中效果很好,另外,您还可以添加过期日期(如果不需要,

在我的一个ASP.Net网站中,我必须提供一个指向用户的链接,其中所有查询字符串参数都应加密

我的想法是使用命令
“aspnet\u regiis”
(用于加密
web.config
数据),将输出作为已发布url中的查询字符串传递

当用户单击该链接时,我首先解密字符串,然后获取查询字符串的原始数据


我这样做对吗?有什么好的技术可以加密和解密查询字符串吗?

在ASP.NET上下文中加密和解密字符串的好方法是使用

它似乎只适用于cookie,但在其他上下文中效果很好,另外,您还可以添加过期日期(如果不需要,也可以添加DateTime.MaxValue),这是一个示例代码:

public static string Encrypt(string content, DateTime expiration)
{
    return FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1,
        HttpContext.Current.Request.UserHostAddress, // or something fixed if you don't want to stick with the user's IP Address
        DateTime.Now, expiration, false, content));
}

public static string Decrypt(string encryptedContent)
{
    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encryptedContent);
    if (!ticket.Expired)
            return ticket.UserData;

    return null; // or throw...
}

您不需要调用外部应用程序。使用框架内的加密API加密/解密数据。以下是我完成此任务的方法:。这些都内置于ASP.NET中--无需编写自己的加密: