Sample code for 30+ languages & platforms
Unicode C

Get Public Key from Certificate PEM

See more Certificates Examples

Loads a certificate from a PEM file and gets the cert's public key.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkCertW.h>
#include <C_CkPublicKeyW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCertW cert;
    HCkPublicKeyW pubkey;

    success = FALSE;

    cert = CkCertW_Create();

    success = CkCertW_LoadFromFile(cert,L"qa_data/certs/someCert.pem");
    if (success == FALSE) {
        wprintf(L"%s\n",CkCertW_lastErrorText(cert));
        CkCertW_Dispose(cert);
        return;
    }

    // Get the certificate's public key:
    pubkey = CkPublicKeyW_Create();
    CkCertW_GetPublicKey(cert,pubkey);

    wprintf(L"%s\n",CkPublicKeyW_getPem(pubkey,FALSE));

    // OK.. we have the public key which can be used in other Chilkat classes/methods...


    CkCertW_Dispose(cert);
    CkPublicKeyW_Dispose(pubkey);

    }