Sample code for 30+ languages & platforms
C

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkPrivateKey pkey;
    HCkPublicKey pubKey;

    success = FALSE;

    pkey = CkPrivateKey_Create();

    // Load the private key from an PEM file:
    success = CkPrivateKey_LoadPemFile(pkey,"private.pem");
    if (success == FALSE) {
        printf("%s\n",CkPrivateKey_lastErrorText(pkey));
        CkPrivateKey_Dispose(pkey);
        return;
    }

    pubKey = CkPublicKey_Create();
    CkPrivateKey_ToPublicKey(pkey,pubKey);

    success = CkPublicKey_SavePemFile(pubKey,FALSE,"pubKey.pem");
    if (success != TRUE) {
        printf("%s\n",CkPublicKey_lastErrorText(pubKey));
        CkPublicKey_Dispose(pubKey);
        CkPrivateKey_Dispose(pkey);
        CkPublicKey_Dispose(pubKey);
        return;
    }

    printf("Success.\n");


    CkPrivateKey_Dispose(pkey);
    CkPublicKey_Dispose(pubKey);

    }