Sample code for 30+ languages & platforms
DataFlex

PKCS7 Decrypt MIME

See more MIME Examples

Loads a PKCS7 encrypted MIME file and decrypts. The cert and private key used for decryption is loaded from a PFX file.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    String sPfxPassword
    String sTemp1

    Move False To iSuccess

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End

    // Load the MIME
    Get ComLoadMimeFile Of hoMime "encryptedMime.txt" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // The AddPfxSourceFile and/or AddPfxSourceData
    // methods may be called one or more times (one per PFX)
    // to add sources from which the MIME component will
    // search for certificates and private keys when decrypting.
    Move "myPassword" To sPfxPassword
    Get ComAddPfxSourceFile Of hoMime "myCertAndPrivateKey.pfx" sPfxPassword To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

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

    // Display the decrypted MIME:
    Get ComGetMime Of hoMime To sTemp1
    Showln sTemp1


End_Procedure