Sample code for 30+ languages & platforms
DataFlex

Serialize a PFX to BinData

See more PFX/P12 Examples

Demonstrates Pfx.ToBd, which serializes the current PFX contents as PKCS#12 data into a BinData object, using the supplied output password.

Background. This is the in-memory equivalent of ToFile, producing the PKCS#12 bytes for further processing or transport.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoPfx
    String sPassword
    String sOutputPassword
    Variant vBd
    Handle hoBd
    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.
    //  The PFX password should come from a secure source rather than being hard-coded.
    Move "myPfxPassword" To sPassword
    Get ComLoadPfxFile Of hoPfx "qa_data/identity.pfx" sPassword To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Serialize the PFX contents as PKCS#12 data into a BinData, using the given output password.
    Move "myOutputPassword" To sOutputPassword
    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get pvComObject of hoBd to vBd
    Get ComToBd Of hoPfx sOutputPassword vBd To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumBytes Of hoBd To iTemp1
    Showln "Serialized " iTemp1 " bytes of PKCS#12 data."


End_Procedure