c# Revocate certificate in CA using CERTADMINLib

1 Add certadmin lib
enter image description here
For this install http://www.microsoft.com/en-us/download/details.aspx?id=7887

Follow these steps:
1.        Click Start , click Control Panel , and then click Programs .
2.        In the Programs and Features area, click Turn Windows features on or off .
If you are prompted by User Account Control to allow the Windows Features dialog box to open, click Continue .
3.        In the Windows Features dialog box:

Expand Remote Server Administration Tools .
Expand Role Admin Tools .
Expand Active Directory Certificate Services Tools .
Check Certificate Authority Tools.
OK.

In command prompt type this: "tlbimp certadm.dll"

Usefull links about this
http://blogs.msdn.com/b/alejacma/archive/2012/04/04/how-to-get-info-from-client-certificates-issued-by-a-ca-c-vs-2010.aspx
https://social.technet.microsoft.com/forums/windowsserver/en-US/cf809bb4-f172-46f3-86f8-36e43be89a1d/error-adcs-revoke-a-certificate-using-certadminlibdll

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

No comments:

Post a Comment