Sample code for 30+ languages & platforms
DataFlex

Get Public Key from Certificate PEM

See more Certificates Examples

Loads a certificate from a PEM file and gets the cert's public key.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoCert
    Variant vPubkey
    Handle hoPubkey
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End

    Get ComLoadFromFile Of hoCert "qa_data/certs/someCert.pem" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Get the certificate's public key:
    Get Create (RefClass(cComChilkatPublicKey)) To hoPubkey
    If (Not(IsComObjectCreated(hoPubkey))) Begin
        Send CreateComObject of hoPubkey
    End
    Get pvComObject of hoPubkey to vPubkey
    Get ComGetPublicKey Of hoCert vPubkey To iSuccess

    Get ComGetPem Of hoPubkey False To sTemp1
    Showln sTemp1

    // OK.. we have the public key which can be used in other Chilkat classes/methods...


End_Procedure