Sample code for 30+ languages & platforms
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 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/certs/someCert.pem");
    if (success == FALSE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        CkCert_Dispose(cert);
        return;
    }

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

    printf("%s\n",CkPublicKey_getPem(pubkey,FALSE));

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


    CkCert_Dispose(cert);
    CkPublicKey_Dispose(pubkey);

    }