Decrypt file in Java that has been asymmetrically encrypted (AES-256) using OpenSSL (RSA-2048 Public-/Private-Key)

I know this is a hard one... but I encrypt a file in a very standard way using OpenSSL. The file is encrypted in AES-256 using an RSA-2048 Public-Key. I want to decrypt the file in Java using the Private-Key. I researched for a long time and tried a lot of methods, but none seems to work. I just find related problems with working solutions, but not for exactly my problem.

I generate the Public-/Private-Key-Pair using this command:

openssl req -x509 -nodes -days 18250 -newkey rsa:2048
-keyout MyPrivateKey.pem -out MyPublicKey.pem
-subj "/C=CH/O=My Company/CN=My Key"

I encrypt the file using this command:

openssl smime -encrypt -aes256 -in -binary
-outform DEM -out message.dat MyPublicKey.pem

The file can be decrypted using this command:

openssl smime -decrypt -in message.dat -binary
-inform DEM -inkey MyPrivateKey.pem -out

But how can the decryption be done in Java? I know about JCE and I have heard of BouncyCastle. I just find hints, but no working solution.

BTW: It is a requirement and hard constraint that the file is asymmetrically encrypted using OpenSSL and decrypted using Java.

Thanks for your help, experts!


The openssl command line creates CMS messages (specified in PKCS#7). You need the bouncy castle SMIME libraries to process those. The functionality is not in the standard Java API.

Need Your Help

Preventing copy construction and assignment of a return value reference

c++ copy-constructor assignment-operator

If I have a function that returns a reference to an instance of a class that I don't have control over its source, say list<int>:

Trying to override NavigationMode.Back

c# windows-phone-8 back-button

I'm trying to develop a simple app for Windows Phone 8, and there are many requirements for the use of the Back Button. As I don't want the Back Button to simply GoBack in back stack, I'd like to p...