'BouncyCastle java - create S/MIME 4 AuthEnvelopedData encrypted e-mail

I'd like to send S/MIME 4 encrypted e-mail with bouncycastle.

I'm no expert here, but as far as I understood, it boils down to creating AuthEnvelopedData message.

The MIME message should have following content type: Content-Type: application/pkcs7-mime; smime-type=authEnveloped-data;.

However, by searching through bouncycastle examples and by a full text search for authEnveloped-data string in the source code, I couldn't find a way how to create it.

I can see that bouncycastle implements AuthEnvelopedData class, but that seems to be for parsing the incoming messages, while I'm looking for something that implements the message creation.

Note: that sample code here is creating message with content type application/pkcs7-mime; name="smime.p7m"; smime-type=enveloped-data. Which is the SMIME 3 "less secure" variant.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source