Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkPublicKey.pb"
IncludeFile "CkPrivateKey.pb"

Procedure ChilkatExample()

    success.i = 0

    pkey.i = CkPrivateKey::ckCreate()
    If pkey.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Load the private key from an PEM file:
    success = CkPrivateKey::ckLoadPemFile(pkey,"private.pem")
    If success = 0
        Debug CkPrivateKey::ckLastErrorText(pkey)
        CkPrivateKey::ckDispose(pkey)
        ProcedureReturn
    EndIf

    pubKey.i = CkPublicKey::ckCreate()
    If pubKey.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkPrivateKey::ckToPublicKey(pkey,pubKey)

    success = CkPublicKey::ckSavePemFile(pubKey,0,"pubKey.pem")
    If success <> 1
        Debug CkPublicKey::ckLastErrorText(pubKey)
        CkPublicKey::ckDispose(pubKey)

        CkPrivateKey::ckDispose(pkey)
        CkPublicKey::ckDispose(pubKey)
        ProcedureReturn
    EndIf

    Debug "Success."


    CkPrivateKey::ckDispose(pkey)
    CkPublicKey::ckDispose(pubKey)


    ProcedureReturn
EndProcedure