C# 如何加密对Web服务ASMX的响应/请求?
下面是我的小web服务演示:C# 如何加密对Web服务ASMX的响应/请求?,c#,.net-2.0,asmx,C#,.net 2.0,Asmx,下面是我的小web服务演示: [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class ServicePrueba : System.Web.Services.WebService { [WebMethod(Enab
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class ServicePrueba : System.Web.Services.WebService
{
[WebMethod(EnableSession=true)]
public int SayHello()
{
int counter;
if (Context.Session == null)
{
counter = 1;
}
else
{
int tmpCounter = Convert.ToInt32(Context.Session["Counter"]);
counter = tmpCounter + 1;
}
Context.Session["Counter"] = counter;
return counter;
}
}
下面是我如何通过控制台客户端应用程序调用它:
class Program
{
static void Main(string[] args)
{
ServicePrueba serviceProxy = new ServicePrueba();
/*Set the cookie container on the proxy.*/
var cookies = new System.Net.CookieContainer();
serviceProxy.CookieContainer = cookies;
Console.WriteLine(serviceProxy.SayHello());
Console.ReadKey();
Console.WriteLine(serviceProxy.SayHello());
Console.ReadKey();
Console.WriteLine(serviceProxy.SayHello());
Console.ReadKey();
Console.WriteLine(serviceProxy.SayHello());
Console.ReadKey();
Console.WriteLine(serviceProxy.SayHello());
Console.ReadKey();
Console.ReadKey(true);
}
}
我的问题是,通过电线进出的信息是纯文本的不是吗?(有没有办法看到这些数据的样子?)
我如何保护这些敏感信息免受窥探?我只想对消息进行加密,这样当它通过电线传输时就会乱七八糟。您应该使用HTTPS。通过HTTPS连接托管它将解决此问题。您可以通过数据包嗅探工具查看流量,如分析数据包。我很肯定这不是很有用 所以,如果我使用SSL来使用HTTPS,没有人可以获取此信息?正确。通过SSL,所有可能敏感的内容都被加密。唯一可能被认为敏感的是目标服务器。因此,他们会知道你正在连接谁,但理论上无法获得任何其他信息。有一个类似的问题提供了非常有用的答案,但我认为最简单的方法就是使用https