Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to import a private key (RSA) generated outside of Java?

843811Oct 18 2006 — edited Jun 5 2007
Ok ... I'm having a problem with this. If someone could just point me in the right direction, it'd be much appreciated!

I'm using RSA encryption for some data (the private key does not reside on the machine where the public key and the data live). The keys were generated using perl, and I have no problem encrypting/decrpting with perl. I would like to do the decrypt in Java, using the private key. This is not dealing with certificates - I just want to use RSA to encrypt/decrypt some data.

Lets say I have a private key as follows in a file:

-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQC0LYHlad7q76mgo3+7d0HRwuasLdW8BLtySOfnZvL6RAiy2EPy
PRFil5HQbvazBCrywba8I5JDmPzZahFAukG5cjzT3Wl2/N4Uaz7QgBCw+jMClsNP
lLUUsXzXS4NfmeMObf0KVxt8z5IjyE6DyCJFFoIaOBtVYxLViqOGRFXfrQIDAP//
AoGAI7PwIx9/lVkWm7VBcqzyLbymZeBy7HZ0gvfJO3l3uuLaBBoygOBupFHg7IgJ
Vj43qNXfRWLpzGLK7PebZsjO8nLI5jvcCiigiPR889uXKGcjlDIP+Bbwv6hd+wF4
Ttjcxl/1G46/rVY/+aj1F2G8WiyJkh3XHs3cBuS9+K8W46cCQQDhaY8shJbJuGOn
4xzUzOFubsIOFcvbLV2rgy+7ocCRoPLNt0ZI67gBUUbKUH8+ZdHFKCoc8ufvE1gO
RTbmx47PAkEAzKCTcoY0mgFK9p0Lf/zdiv6LPRm9yBrr5w7ajSKb/EYZg1un30QZ
/w0vnKhz3g0wP6kTi7PSm8F9jPIpprBowwJBAMBeTcVTi+IBdU0jZiYgXiIUNz8s
aPycW6RRwHXoJ7ZvCKQHI8ous14TMnSp1sCetPrtmZ3+CVxX5mVUBoZIo28CQBiF
MlBCbx4HV6/mv2CEgFyBHtZgJQLYZK7jkYnM+HfyKk7M0WltRX66Zjfu01kl87cE
jJEhDFSgQxifuSdneOUCQDsl6vWOiSSpnsucF4s4aFWoa/eRzT7pb7BkBAoggoOZ
NoiIgxlnctxlIX2d8r3xv+BFM8TFsj3Sdezbt1w6Jyo=
-----END RSA PRIVATE KEY-----

How do I bring this key into Java (say I read it into a string from a file), so I can use it to decrypt the data? I think I understand the basics of how to generate keys in java and use them from researching it on the net (I understand using bouncycastle for RSA provider), I'm just having a hard time figuring out how to import a key such as the one shown above.

Thank you in advance,
- Brian Roach
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 3 2007
Added on Oct 18 2006
3 comments
419 views