• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Storing Keys in KeyStore

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can not simply make sense of this KeySTore Class.

I have private and public key and I simply want to use them in KeyStore to use later.

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); java.security.NoSuchProviderException
keyGen.initialize(512 , random);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey priKey = keypair.getPrivate();
PublicKey pubKey = keypair.getPublic();


File f = new File("c:\keystore");
// Create an empty keystore object
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());

???
// code to store private and public key in keystore

// Save the new keystore contents
FileOutputStream out = new FileOutputStream(keystoreFile);
keystore.store(out, password.toCharArray());
out.close();


Can some one please help me with missing code.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Installing Providers.

You can also use the keytool utility to store certificates.

Regards, Jan
 
Shariq Roomi
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jan but I want to do programmatically.

There is a function in KeySTore class

setKeyEntry(String alias, Key key, char[] password, Certificate[] chain)
Assigns the given key to the given alias, protecting it with the given password.

So I am wondering hwo could I get the corresponding Certficate array for my privatekey ??
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic