Sample code for 30+ languages & platforms
DataFlex

Load a Public Key from BinData

Demonstrates the Chilkat PublicKey.LoadBd method, which loads a public key from the bytes in a BinData. The only argument is the BinData, which may contain binary DER or any textual representation recognized by LoadFromString.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: When key bytes are already in memory — downloaded, extracted from a container, or pulled from a database — this loads them directly with no temporary file. It applies the same content inspection as the string and file loaders, so it accepts both binary DER and any recognized text form. It is the in-memory counterpart to LoadFromFile.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vBd
    Handle hoBd
    Handle hoPubKey
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the PublicKey.LoadBd method, which loads a public key from the bytes in a BinData.
    //  The only argument is the BinData, which may contain binary DER or any textual representation
    //  recognized by LoadFromString.

    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get ComLoadFile Of hoBd "qa_data/public.der" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoBd To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatPublicKey)) To hoPubKey
    If (Not(IsComObjectCreated(hoPubKey))) Begin
        Send CreateComObject of hoPubKey
    End
    Get pvComObject of hoBd to vBd
    Get ComLoadBd Of hoPubKey vBd To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPubKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComKeyType Of hoPubKey To sTemp1
    Showln "Loaded a " sTemp1 " public key."


End_Procedure