使用ICertAdmin2 :: RevokeCertificate方法撤销c#中的证书

时间:2009-08-04 12:56:31

标签: c# certificate-authority

如何将certadm.dll导入托管项目并使用RevokeCertificate方法?我尝试添加它作为参考,但我得到错误,因为它不是汇编或COM对象。

有什么想法吗?

更新:我已经尝试了 regsvr32 c:\ certadm.dll ,我收到以下错误消息: LoadLibrary(“c:\ certadm.dll”)失败 - 找不到指定的程序。

2 个答案:

答案 0 :(得分:2)

我知道这是一个非常古老的问题,但我找不到在c#中使用ICertAdmin2 :: RevokeCertificate的任何示例。我认为在这里写exaple是有用的。

1添加certadmin lib

enter image description here

2使用此代码

public static void RevokeCert(string connection,string serial)
{
    //connection= "192.168.71.128\\My-CA"
    //serial = "614870cd000000000014"

    const int CRL_REASON_UNSPECIFIED = 0;

    CERTADMINLib.CCertAdmin _admin = null;
    try
    {
        _admin = new CCertAdmin();
        _admin.RevokeCertificate(connection, serial, CRL_REASON_UNSPECIFIED, DateTime.Now);
    }
    finally
    {
        if (_admin != null)
            Marshal.FinalReleaseComObject(_admin);
    }
}

答案 1 :(得分:0)

首先需要使用regsvr32注册COM服务器,然后才能在Visual Studio中添加它作为参考。

如,

regsvr32 certadm.dll