Sample code for 30+ languages & platforms
C

Get Certificate's Public Key

Loads a certificate from PEM and gets the public key.

Chilkat C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkCert cert;
    const char *strPem;
    HCkPublicKey pubKey;

    success = FALSE;

    cert = CkCert_Create();

    strPem = "-----BEGIN CERTIFICATE----- ...";

    success = CkCert_LoadPem(cert,strPem);
    if (success == FALSE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkCert_Dispose(cert);
        return;
    }

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

    //  You can now use the public key object however it is needed,
    //  and access its various properties and methods..

    printf("%s\n",CkPublicKey_getXml(pubKey));


    CkCert_Dispose(cert);
    CkPublicKey_Dispose(pubKey);

    }