Sample code for 30+ languages & platforms
C

Convert to DER encoded X.509 Certificate (.cer, .crt)

See more Certificates Examples

Loads a digital certificate from any format and saves to a binary DER encoded X.509 Certificate (.cer, .crt).

Chilkat C Downloads

C
#include <C_CkCert.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCert cert;

    success = FALSE;

    cert = CkCert_Create();

    // LoadFromFile will load virtually any certificate format file.
    // It will auto-recognize the format and load appropiately.
    // In this case, load a PEM format certificate and convert to DER.
    success = CkCert_LoadFromFile(cert,"/Users/chilkat/testData/pem/chilkat.pem");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkCert_Dispose(cert);
        return;
    }

    success = CkCert_ExportCertDerFile(cert,"chilkat.der");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkCert_Dispose(cert);
        return;
    }

    printf("Converted certificate from PEM to DER format.\n");


    CkCert_Dispose(cert);

    }