【问题标题】:Revoking certificate in c# with ICertAdmin2::RevokeCertificate method使用 ICertAdmin2::RevokeCertificate 方法在 c# 中撤销证书
【发布时间】:2020-02-27 04:07:04
【问题描述】:

如何将 certadm.dll 导入托管项目并使用 RevokeCertificate 方法?我尝试将其添加为参考,但由于它不是程序集或 COM 对象而出现错误。

有什么想法吗?

更新: 我已经尝试过 regsvr32 c:\certadm.dll,但出现以下错误: LoadLibrary("c:\certadm.dll") 失败 - 找不到指定的过程。

【问题讨论】:

标签: c# certificate-authority


【解决方案1】:

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

1 添加 certadmin 库

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);
    }
}

【讨论】:

  • 添加到这个答案,要创建 certadminLib 我必须运行“tlbimp certadm.dll”来创建它。
【解决方案2】:

您首先需要使用regsvr32 注册 COM 服务器,然后才能将其添加为 Visual Studio 中的引用。

例如,

regsvr32 certadm.dll

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-25
    • 2011-01-13
    • 1970-01-01
    • 2013-05-01
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多