Sample code for 30+ languages & platforms
C

Transition from Crypt2.GetSignerCertChain to Crypt2.LastSignerCert

Provides instructions for replacing deprecated GetSignerCertChain method calls with LastSignerCert.

Chilkat C Downloads

C
#include <C_CkCrypt2.h>
#include <C_CkCertChain.h>
#include <C_CkCert.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCrypt2 crypt2;
    int index;
    HCkCertChain certchainObj;
    HCkCert signerCert;
    HCkCertChain certChain;

    success = FALSE;

    crypt2 = CkCrypt2_Create();

    //  ...
    //  ...
    index = 0;

    //  ------------------------------------------------------------------------
    //  The GetSignerCertChain method is deprecated:

    certchainObj = CkCrypt2_GetSignerCertChain(crypt2,index);
    if (CkCrypt2_getLastMethodSuccess(crypt2) == FALSE) {
        printf("%s\n",CkCrypt2_lastErrorText(crypt2));
        CkCrypt2_Dispose(crypt2);
        return;
    }

    //  ...
    //  ...

    CkCertChain_Dispose(certchainObj);

    //  ------------------------------------------------------------------------
    //  Do the equivalent using LastSignerCert, and then get the certificate chain from the cert.
    //  Your application creates a new, empty Cert object which is passed 
    //  in the last argument and filled upon success.

    signerCert = CkCert_Create();
    success = CkCrypt2_LastSignerCert(crypt2,index,signerCert);
    if (success == FALSE) {
        printf("%s\n",CkCrypt2_lastErrorText(crypt2));
        CkCrypt2_Dispose(crypt2);
        CkCert_Dispose(signerCert);
        return;
    }

    certChain = CkCertChain_Create();
    success = CkCert_BuildCertChain(signerCert,certChain);
    if (success == FALSE) {
        printf("%s\n",CkCert_lastErrorText(signerCert));
        CkCrypt2_Dispose(crypt2);
        CkCert_Dispose(signerCert);
        CkCertChain_Dispose(certChain);
        return;
    }



    CkCrypt2_Dispose(crypt2);
    CkCert_Dispose(signerCert);
    CkCertChain_Dispose(certChain);

    }