Sample code for 30+ languages & platforms
PureBasic

Get Certificate Public Key from PEM

See more Certificates Examples

Demonstrates how to load a PEM file containing a certificate and access the public key.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkPublicKey.pb"
IncludeFile "CkCert.pb"

Procedure ChilkatExample()

    success.i = 0

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

    success = CkCert::ckLoadFromFile(cert,"qa_data/pem/my_cert.pem")
    If success = 0
        Debug CkCert::ckLastErrorText(cert)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

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

    CkCert::ckGetPublicKey(cert,pubkey)

    ; Examine the public key as XML..
    Debug CkPublicKey::ckGetXml(pubkey)


    CkCert::ckDispose(cert)
    CkPublicKey::ckDispose(pubkey)


    ProcedureReturn
EndProcedure