Advertisement

04.25.2008 at 06:19AM PDT, ID: 23353350
[x]
Attachment Details

Java KeyGen and Cert question

Asked by LiamOB in Java Programming Language, Miscellaneous Security

Tags: Java

I'm using KeyPairGenerator to create a public and private key. I then want to save the private key in a keystore file and generate a cert which holds the public key.

I can generate the keys and store the private key in the keystore (i think) but I'm looking for some help on how to create the cert from the public key. Also do I need to put the cert/public key in the keystore too?


This is what i have so far:Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
public void generateUserKeystoreAndCert(String alias,String keystore, String password, String certfile)
  {
 
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    ks.load(null,password.toCharArray());
 
 
    KeyPairGenerator kg = KeypairGenerator.getInstance("SHA1withRSA");
    kg.initialize(1024);
    KeyPair keyPair = kg.generateKeyPair();
    PrivateKey privateKey = keyPair.getPrivate();
    PublicKey publicKey = keyPair.getPublic();
 
    ks.setEntry(alias,privateKey,password);
 
    FileOutputStream fos = new FileOutputStream(keystore);
    ks.store(fos,password);
    fos.close();
    System.out.println("One keystore has been created.");
 
//Now to create a cert ....
 
 
[+][-]04.25.2008 at 10:50AM PDT, ID: 21441764

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, Miscellaneous Security
Tags: Java
Sign Up Now!
Solution Provided By: mbodewes
Participating Experts: 1
Solution Grade: B
 
 
[+][-]04.25.2008 at 10:52AM PDT, ID: 21441778

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 11:01AM PDT, ID: 21441858

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628