Revoking certificate in c# with ICertAdmin2::Revok

2019-07-23 05:03发布

问题:

How to import certadm.dll into managed project and use RevokeCertificate method? I tried adding it as reference but I got error asying it's not assembly or COM object.

Any ideas?

UPDATE: I already tried regsvr32 c:\certadm.dll and I get following error: LoadLibrary("c:\certadm.dll") failed - the specified procedure could not be found.

回答1:

I know this is very old question, but i cannot find any example of using ICertAdmin2::RevokeCertificate in c#. I think it is usefull to write exaple here.

1 Add certadmin lib

2 Use this code

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


回答2:

You first need to register the COM server using regsvr32 before it will be available to be added as a reference in Visual Studio.

e.g.,

regsvr32 certadm.dll