Get the public key of a website#39;s SSL certificate(获取网站 SSL 证书的公钥)
问题描述
我不确定以下是否可行,因为我绝不是该主题(安全、证书等)方面的专家.
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# 代码获取网站 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 来实现彼此之间的信任状态.因此,假设 Site1
向 Site2
发出请求,并向其发送了一个令牌,该令牌应该来自受信任的授权服务器.Site2
应该能够验证此令牌的真实性.
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.
我希望这已经足够清楚了.
I hope that was clear enough.
推荐答案
我将以下代码块用于类似目的.希望对你有帮助!!!
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 证书的公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取网站 SSL 证书的公钥
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01