Sample code for 30+ languages & platforms
PureBasic

Get Certificate's Public Key

Loads a certificate from PEM and gets 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

    strPem.s = "-----BEGIN CERTIFICATE----- ..."

    success = CkCert::ckLoadPem(cert,strPem)
    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)

    ; You can now use the public key object however it is needed,
    ; and access its various properties and methods..

    Debug CkPublicKey::ckGetXml(pubKey)


    CkCert::ckDispose(cert)
    CkPublicKey::ckDispose(pubKey)


    ProcedureReturn
EndProcedure