Sample code for 30+ languages & platforms
DataFlex

Add a PFX Source from BinData

See more Email Object Examples

Demonstrates the Chilkat Email.AddPfxSourceBd method, which adds PFX data held in a BinData object to the list of certificate and private-key sources used during decryption or signing. The second argument is the PFX password. Call it before obtaining the encrypted email so Chilkat can decrypt it automatically. This example loads a PFX into a BinData, adds it, and then loads an encrypted email.

Background: This is the in-memory (BinData) counterpart to AddPfxSourceFile. It is the right choice when the PFX bytes come from somewhere other than a file — a database, a secrets manager, or an HTTP download — letting you supply the certificate and private key without first writing them to disk (which is preferable for sensitive key material).

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Variant vBdPfx
    Handle hoBdPfx
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Demonstrates the AddPfxSourceBd method, which adds PFX data (held in a BinData) to the
    //  list of certificate and private-key sources used during decryption or signing.  The
    //  second argument is the PFX password.  Call it before obtaining the encrypted email.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    //  Load PFX data into a BinData object.
    Get Create (RefClass(cComChilkatBinData)) To hoBdPfx
    If (Not(IsComObjectCreated(hoBdPfx))) Begin
        Send CreateComObject of hoBdPfx
    End
    Get ComLoadFile Of hoBdPfx "qa_data/certs/decryption.pfx" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoBdPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Add the PFX as a source of the certificate + private key.
    Get pvComObject of hoBdPfx to vBdPfx
    Get ComAddPfxSourceBd Of hoEmail vBdPfx "pfx_password" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Load an encrypted email; Chilkat decrypts it using the PFX source.
    Get ComLoadEml Of hoEmail "qa_data/eml/encrypted.eml" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComDecrypted Of hoEmail To bTemp1
    Showln "Decrypted = " bTemp1

    //  Note: Paths such as "qa_data/..." are relative local filesystem paths,
    //  relative to the current working directory of the running application.


End_Procedure