How to store my openssl-generated RSA keys to a SUN keystore?

I'm completely new to these security stuff. All I need is to get a RSA encrypted string from our client through http and decrpt it with a RSA private key.

The keys are generated in OpenSSL.

So far, I've been able to decrypt the encrypt string by doing following steps:

1. use OpenSSL tool to make the key in a PKCS8 format.

2. construct a private key object from key material( bytes)

PKCS8EncodedKeySpec pkcs8SpecPriv =new PKCS8EncodedKeySpec(getBytesFromFile(privKeyFileName));

PrivateKey privKey = rsaKeyFactory.generatePrivate( pkcs8SpecPriv);

3.construct a RSA cipher and call doFinal method to decrpyt the string.

Now my supervisor asks me to put these keys into a standard keystore so our Java code can read the private key from this keystore since it's more maintainable to do this way than constructing a key from a physical key file somewhere on the hard drive.

I read the doc about "keytool", but not quite understand all those concepts yet. All I know right now is, in order to execute "keytool -import"( I guess this is the command I need), I need some sort certificate. I don't understand this part, what i imaged, or the most straightforward way I thought of is, store this pair of RSA keys( public and private) in a keystore the way some sort like a hashtable, then I can retrieve them by calling a method with their alias name. Obviously, it's not working this way, can somebody give me a simple explaination on how this certificate is needed in my scenario and what I should do for my simple needs( getting keys from a keystore).

Any hint will be appreciated.

[1682 byte] By [jobseekera] at [2007-9-24]
# 1

Well, I can tell you that much. The KeyStore class lets you store certificates, which holds public/private keys. A certificate is needed to

authenticate yourself. You can sign a document or an email using a certificate, but in your case I don't see the need of a certificate, and

therefore the KeyStore class might not be the right way. I've added two two links though, which I found helpful understanding the KeyStore

class and its associated classes:

http://java.sun.com/j2se/1.5.0/docs/guide/security/CryptoSpec.html

http://www.developer.com/security/article.php/3105261

ringlera at 2007-7-14 > top of java,Security,Cryptography...