Sample code for 30+ languages & platforms
DataFlex

Add PFX Bytes as a Decryption Source

See more MIME Examples

Loads a CMS/PKCS #7 encrypted S/MIME message and decrypts it back to the original MIME content.

AddPfxSourceBd registers PFX/P12 bytes held in a BinData as a source of certificates and private keys for later decryption.

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. This is the in-memory equivalent of AddPfxSourceFile, for cases where the PKCS #12 data is already loaded into a BinData rather than residing in a file.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    Variant vBdPfx
    Handle hoBdPfx
    String sPfxPassword
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End
    Get ComLoadMimeFile Of hoMime "qa_data/encrypted.eml" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Add PFX/P12 bytes (from a BinData) as a source of certificates and private keys for later
    //  decryption.  The 1st argument is the BinData and the 2nd is the password (from a secure source).
    Get Create (RefClass(cComChilkatBinData)) To hoBdPfx
    If (Not(IsComObjectCreated(hoBdPfx))) Begin
        Send CreateComObject of hoBdPfx
    End
    Get ComLoadFile Of hoBdPfx "qa_data/recipient.pfx" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoBdPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Move "myPfxPassword" To sPfxPassword
    Get pvComObject of hoBdPfx to vBdPfx
    Get ComAddPfxSourceBd Of hoMime vBdPfx sPfxPassword To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComDecrypt Of hoMime To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Decrypted."


End_Procedure