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 证书的公钥
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
