In an application I want to store sensitive data (which can be arbitrarily large) so that it can later be used for researching. The point is that I don't want the data to lie around unprotected, so I want to encrypt it before saving it.
On another computer (in a more trustworthy environment) I want to decrypt that data later. The decryption should be possible with readily available tools, for example OpenSSL. Now my question is: How do I do all that?
I already know the abstract steps:
- Once and for all generate a public/private key pair.
- Encrypt a
byte[]
in Java using the public key, store it somewhere. - Copy the encrypted data to a "safer" computer.
- Decrypt the saved data using a simple OpenSSL command line.
What I'm missing now are the details:
- What kind of key pair do I need?
- What encryption scheme should I use? (it's probably something like "rsa-encrypt a symmetric key, then encrypt the data with that key")
- How does the simple OpenSSL command line look like?
[Update 2011-02-13]
After a little research I found a page that describes exactly what I want to do: http://blog.altudov.com/2010/09/27/using-openssl-for-asymmetric-encryption-of-backups/. Basically the answer to my step 4 is this command line:
openssl smime -decrypt \
-in data.smime -binary -inform DER \
-inkey key.pem \
-out data
Now my question is: How can I generate a file from Java whose format is compatible to OpenSSL so I can decompress it using this command line? I want to do this hundrets of times per second, so invoking an external process seems too slow. That's why I want to do it directly in Java.