Revoking certificate in c# with ICertAdmin2::RevokeCertificate method

不想你离开。 提交于 2019-12-24 00:26:17

问题


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


来源:https://stackoverflow.com/questions/1227367/revoking-certificate-in-c-sharp-with-icertadmin2revokecertificate-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!