Sample code for 30+ languages & platforms
DataFlex

Load a PFX from BinData

See more PFX/P12 Examples

Demonstrates Pfx.LoadPfxBd, which loads a PFX / PKCS#12 container from the bytes held in a BinData object.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. This is the in-memory equivalent of LoadPfxFile, for when the PKCS#12 data is already available as bytes rather than in a file.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoPfx
    Variant vBd
    Handle hoBd
    Boolean iBLoaded
    String sPassword
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatPfx)) To hoPfx
    If (Not(IsComObjectCreated(hoPfx))) Begin
        Send CreateComObject of hoPfx
    End

    //  The file path is relative to the application's current working directory.  An absolute path
    //  may also be used.  Supply the path appropriate to your own environment.
    //  Load the PFX bytes into a BinData.
    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get ComLoadFile Of hoBd "qa_data/identity.pfx" To iBLoaded
    If (iBLoaded <> True) Begin
        Showln "Failed to load the PFX file."
        Procedure_Return
    End

    //  The PFX password should come from a secure source rather than being hard-coded.
    Move "myPfxPassword" To sPassword

    //  Load the PFX / PKCS#12 container from the bytes held in the BinData.
    Get pvComObject of hoBd to vBd
    Get ComLoadPfxBd Of hoPfx vBd sPassword To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumCerts Of hoPfx To iTemp1
    Showln "Loaded " iTemp1 " certificate(s)."


End_Procedure