Sample code for 30+ languages & platforms
C

Get Certificate Public Key from PEM

See more Certificates Examples

Demonstrates how to load a PEM file containing a certificate and access the public key.

Chilkat C Downloads

C
#include <C_CkCert.h>
#include <C_CkPublicKey.h>

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

    success = FALSE;

    cert = CkCert_Create();

    success = CkCert_LoadFromFile(cert,"qa_data/pem/my_cert.pem");
    if (success == FALSE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkCert_Dispose(cert);
        return;
    }

    pubkey = CkPublicKey_Create();
    CkCert_GetPublicKey(cert,pubkey);

    // Examine the public key as XML..
    printf("%s\n",CkPublicKey_getXml(pubkey));


    CkCert_Dispose(cert);
    CkPublicKey_Dispose(pubkey);

    }