How to insert a Publickey in a Keystore file without using keytoland wihtout a cert file ?

P

Pedro Martins

After i read java.security.cert and java.security.keystore i didn't find
any solution of my problem.
The problem is that i want to create n keystores without using the
keytool because i want to export the solution to use with smartcards.
This issue i can do it.
The big problem is after created the public and private key (RSA 1024)
the keystore only allows entry Keystore.PrivateKeyEntry (private key +
certificate chain for the corresponding public key)
How can i do this?
Creat a autocertificate file wiht keytool?
Because i wanted to do with code
Thank you for all the help
 
R

robert

Pedro Martins escreveu:
After i read java.security.cert and java.security.keystore i didn't find
any solution of my problem.
The problem is that i want to create n keystores without using the
keytool because i want to export the solution to use with smartcards.
This issue i can do it.
The big problem is after created the public and private key (RSA 1024)
the keystore only allows entry Keystore.PrivateKeyEntry (private key +
certificate chain for the corresponding public key)
How can i do this?
Creat a autocertificate file wiht keytool?
Because i wanted to do with code
Thank you for all the help

Not sure I understand your question. Lets try to focus on what the
Private Key can do and what you want it to do:

PrivateKey pk = null;
java.security.KeyStore ks =
java.security.KeyStore.getInstance(storetype)

pk = (PrivateKey)ks.getKey(privateKeyAlias,
privateKeyPass.toCharArray());

Now, you can store this pk somewhere because it implements
'serializable' . That means it can be store in LDAP for example using
java.schema .

Now you typically need a public key to sign something, often with X509
- which also implements 'serializable' .

X509Certificate cert =
(X509Certificate)ks.getCertificate(privateKeyAlias);

sig.addKeyInfo(cert);
sig.addKeyInfo(cert.getPublicKey());
// Sign the XML Signature document with our private key
sig.sign(privateKey);

Does the above solve, or not solve, your problem? It seems like you
can´t create the cert - not sure why.

HTH,
iksrazal
http://www.braziloutsource.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top