Software AG Products 10.7 | Integrating On-Premises and Cloud Applications | Managing MIME messages | Extracting Data from MIME and S/MIME Messages | Extracting the Payload from an Encrypted MIME Message | How to Extract the Payload from an Encrypted S/MIME Message
 
How to Extract the Payload from an Encrypted S/MIME Message
The following procedure describes the general steps you take to extract data from an encrypted S/MIME message.
1. If you do not know whether the message is encrypted, pass it to the pub.mime:createMimeData service. Afterwards, test the state of the encrypted output parameter. If its value is “true,” proceed to the next step 2. Otherwise, test the signed variable to see whether the message is signed and process it as described in Extracting the Payload from a Signed MIME Message. If the message is neither signed nor encrypted, process it as an ordinary MIME message as described in Extracting the Payload from a MIME Message.
2. Pass the message to the pub.smime.keystore:processEncryptedData to be decrypted. You must pass three input parameters to this service: the InputStream containing the encrypted MIME message, the keystore alias that points to the recipient’s keystore, and the key alias that identifies the recipient’s private key in the keystore.
Keep in mind that if the message was passed to createMimeData prior to this step, the original InputStream will be empty. In this case, you must pass the stream output variable produced by createMimeData to the processEncryptedData service.
Note:
Depending on the nature of the messages your service receives, you may want to test the signed output variable after decrypting the message. This will tell you whether the message had been signed prior to being encrypted. If signed is “true,” you will need to verify the signature of the message in stream. For procedures, see Extracting the Payload from a Signed MIME Message.
3. Extract the payload from the MIME object using the pub.mime:getBodyPartContent service. If the decrypted message is not signed, the MIME object returned by processEncryptedData will contain the message’s constituent elements. You use getBodyPartContent to retrieve the content from this MIME object. For information about using getBodyPartContent, see Extracting the Payload from a MIME Message.