Sample code for 30+ languages & platforms
Unicode 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 Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkPrivateKeyW pkey;
    HCkPublicKeyW pubKey;

    success = FALSE;

    pkey = CkPrivateKeyW_Create();

    // Load the private key from an PEM file:
    success = CkPrivateKeyW_LoadPemFile(pkey,L"private.pem");
    if (success == FALSE) {
        wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(pkey));
        CkPrivateKeyW_Dispose(pkey);
        return;
    }

    pubKey = CkPublicKeyW_Create();
    CkPrivateKeyW_ToPublicKey(pkey,pubKey);

    success = CkPublicKeyW_SavePemFile(pubKey,FALSE,L"pubKey.pem");
    if (success != TRUE) {
        wprintf(L"%s\n",CkPublicKeyW_lastErrorText(pubKey));
        CkPublicKeyW_Dispose(pubKey);
        CkPrivateKeyW_Dispose(pkey);
        CkPublicKeyW_Dispose(pubKey);
        return;
    }

    wprintf(L"Success.\n");


    CkPrivateKeyW_Dispose(pkey);
    CkPublicKeyW_Dispose(pubKey);

    }