获取网站 SSL 证书的公钥

Get the public key of a website#39;s SSL certificate(获取网站 SSL 证书的公钥)

本文介绍了获取网站 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 来实现彼此之间的信任状态.因此,假设 Site1Site2 发出请求,并向其发送了一个令牌,该令牌应该来自受信任的授权服务器.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 证书的公钥

基础教程推荐