获取一个网站的SSL证书的公钥 [英] Get the public key of a website's SSL certificate
问题描述
我真的不知道是否是因为我下面是可行与否绝不是关于这个问题的专家(安全证书...等)。
I'm not really sure about whether the following is doable or not because I'm in no way an expert on the subject (security, certificates...etc).
不管怎样,我想要做的就是使用C#code网站的SSL证书的公钥。就像是有办法使用一个HTTP请求或东西来查询从网站的信息?
Anyway, what I want to do is get the Public Key of a website's SSL certificate using C# code. Like is there a way to query that information from the site using an HTTP request or something?
为了让你们明白,为什么我真的想这样做,我会简单介绍一下我想要发生的情况。基本上我有为数众多的使用OAuth 2.0来实现彼此之间的信任状态网站。所以我们说站点1
发出站点2
的请求,并送了它一个令牌按理说它是来自受信任的授权服务器。 站点2
应该可以验证此令牌的真实性。
In order for you guys to understand why I really want to do so, I'll briefly explain the scenario I want to make happen. Basically I have a bunch of websites that use OAuth 2.0 to achieve a state of trust among each other. So let's say Site1
issued a request to Site2
and sent it a token which is supposedly from a trusted Authorization Server. Site2
should be able to verify the authenticity of this token.
我希望那是不够清楚。
推荐答案
我用code以下块类似的目的。我希望它能帮助!
I use the following block of code for a similar purpose. I hope it helps!!!
Uri u = new Uri(url);
ServicePoint sp = ServicePointManager.FindServicePoint(u);
string groupName = Guid.NewGuid().ToString();
HttpWebRequest req = HttpWebRequest.Create(u) as HttpWebRequest;
req.ConnectionGroupName = groupName;
using (WebResponse resp = req.GetResponse())
{
}
sp.CloseConnectionGroup(groupName);
byte[] key = sp.Certificate.GetPublicKey();
return key;
这篇关于获取一个网站的SSL证书的公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!