通过C#从目标元数据库实例获取特定证书 [英] Get a specific certificate by the targeted metabase instance from C#

查看:72
本文介绍了通过C#从目标元数据库实例获取特定证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

 

我正在编写一小段代码,其唯一目的是从本地计算机存储中获取特定证书并将其写入文件中.

I am writing a small piece of code that it sole purpose is to get a specific certificate from the local machine store and write it to a file.

 

问题:

在IIS6上,我使用脚本(请参见下文)获取证书.我可以选择通过实例名称唯一标识它(标识目标配置数据库实例,即/LM/W3SVC/1/ROOT/NameOFWebService). IIS7相当于什么?

On IIS6, I use scripting (see below) to get the certificate. I have the option to uniquely identify it by the Instance name (Identifies the targeted metabase instance, i.e. /LM/W3SVC/1/ROOT/NameOFWebService). What will be the equivalent for IIS7?

 

其他信息:

1.> 这将在Web服务器上运行.

1.      This will run on the web server.

2.> 每次都会有不同的用户,因为不同的客户会运行它(所以我不能按属性过滤).

2.      Every time it will be a different one as different customers will run it (so I can’t filter by attribute).

3.> 我正在使用.NET而不是脚本,因为我需要使用IIS6和IIS7为客户服务(请继续阅读,我会澄清).

3.      I am using .NET not scripting as I need to serve customers with IIS6 and IIS7 (keep reading, I will clarify).

 

在IIS6上,我可以使用以下VBScript:

Dim iiscertobj

Dim iiscertobj

设置iiscertobj = WScript.CreateObject("IIS.CertObj")

Set iiscertobj = WScript.CreateObject("IIS.CertObj")

iiscertobj.InstanceName ="/LM/W3SVC/1/ROOT/NameOFWebService""

iiscertobj.InstanceName = "/LM/W3SVC/1/ROOT/NameOFWebService"

iiscertobj.ServerName ="127.0.0.1"

iiscertobj.ServerName = "127.0.0.1"

iiscertobj.Export"PathToFile \ cert.pfx","pw",false,false,false

iiscertobj.Export "PathToFile\cert.pfx", "pw", false, false, false

 

这在IIS6上效果很好.要在IIS7上使用相同的脚本,我将需要安装IIS6兼容性包,这是不可能的.

This works great on IIS6. To use the same script on IIS7 I will need to install the IIS6 compatibility pack, this is not possible.

这就是为什么我决定简化.NET代码以获取证书的原因:

This is why I decided to facilitate the .NET code to get the certificate:

 

           //获取当前用户的证书存储.

            // Get the certificate store for the current user.

           X509Store store =新的X509Store(StoreLocation.LocalMachine);

            X509Store store = new X509Store(StoreLocation.LocalMachine);

          尝试

            try

           {

            {

               store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

               //将所有证书放在X509Certificate2Collection对象中.

                // Place all certificates in an X509Certificate2Collection object.

               X509Certificate2Collection certCollection = store.Certificates;

                X509Certificate2Collection certCollection = store.Certificates;

               X509Certificate2Collection currentCerts = certCollection.Find(...); ß ------这是我需要帮助的地方

                X509Certificate2Collection currentCerts = certCollection.Find(...); ß------ here is where I need help

           }

            }

           catch(异常e)

            catch(Exception e)

           {

            {

...

           }

            }

          终于

            finally

           {

            {

               store.Close();

                store.Close();

           }

            }

 

注意:.NET解决方案可同时在IIS6和IIS7上运行.请随时提出一个完全不同的解决方案.

Note: the .NET solution is working on both IIS6 and IIS7. Please feel free to suggest an entirely different solution.

 

问题:

1.> 如何找到特定Web服务的证书?与我在VBScript中找到的相同(请参见上文):iiscertobj.InstanceName ="/LM/W3SVC/1/ROOT/NameOFSite"?使用.NET,我只能通过以下方式进行过滤:

1.      How do I find the certificate of a specific web service? The same as I found it with the VBScript  (see above): iiscertobj.InstanceName = "/LM/W3SVC/1/ROOT/NameOFSite"? with .NET I can only filter by:

http ://msdn.microsoft.com/zh-CN/library/system.security.cryptography.x509certificates.x509findtype(v = VS.90).aspx

2.> 是否可以通过编程方式检查特定网站是否启用了SSL?对于IIs6/IIS7?

2.      Is there a way to programmatically check if a specific website is SSL enabled? For IIs6 / IIS7?

 

如果您需要更多信息,请告诉我...

Let me know if you need more information...

 

谢谢

Rotem Varon

Rotem Varon

推荐答案

Rotem,

我们正在根据您的要求进行研究,如果有任何结果,我们会尽快与您联系.

祝你有美好的一天,
Hi Rotem,

We are doing some research on your requirement, if any result is got we will get back to you ASAP.

Have a nice day,


这篇关于通过C#从目标元数据库实例获取特定证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆