Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Security and the fly likes Load my private key to keystore(problem in loading private key to key store) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "Load my private key to keystore(problem in loading private key to key store)" Watch "Load my private key to keystore(problem in loading private key to key store)" New topic
Author

Load my private key to keystore(problem in loading private key to key store)

Harish Ponduri
Greenhorn

Joined: Jun 08, 2009
Posts: 19
Hi Everyone,

I am trying to load the keystore with the private key and password, but i am facing an exception.
Here the exception is :
java.io.IOException: Wrong version of key store.
at org.bouncycastle.jce.provider.JDKKeyStore.engineLoad(Unknown Source)
at java.security.KeyStore.load(KeyStore.java:1150)
at XML.Decryptor.keystoreTest(Decryptor.java:329)
at XML.Decryptor.main(Decryptor.java:349)

my Code is :

String passPhrase="password";
FileInputStream privKey = null;
privKey = new FileInputStream("C:/TEMP/secring.asc");
KeyStore ks = KeyStore.getInstance("BKS");
ks.load(privKey, passPhrase.toCharArray());

here privKey is the Private key generated using open pgp boouncy castle encryption, and i want to store this in the keystore of BKS.

Cansomeone please help me, I am not able to understand how to proceed, even googling doesnt helped me.
Correct me in the above way of doing if my approach is wrong.

thank you in advance.

Regards,
Harish Ponduri.
greg stark
Ranch Hand

Joined: Aug 10, 2006
Posts: 220
A PGP keyring cannot be used as a KeyStore. It is not compatible with, or related in any way to, a Bouncycastle keystore, nor any of Sun's keystores. You must use the methods of the bouncycastle PGP api to process PGP keys and messages.


Nice to meet you.
Harish Ponduri
Greenhorn

Joined: Jun 08, 2009
Posts: 19
Hi Greg stark

thank you very much for your valuable reply.

So, could you please suggest me or give any idea on my requirement.

My Requirement:

I got a PGP-private key by which i am able to decrypt my encrypted files, and do all the stuff.

so now in my current implementation i am using keystore object to load and by which i am decrypting some data (it is different from my above bouncy castle implementation)

so my requirement is can i even load my PGP Private key in the keystore, so that i will retrieve them on individual alias name and use for their purpose.

can this be implemented, or do we have any other way of loading my PGP private key to KeyStore(NOT to JAVA keystore some other related to bouncy, if it exists).


thank you,


Ponduri.
greg stark
Ranch Hand

Joined: Aug 10, 2006
Posts: 220
if by keystore you mean the KeyStore class, then no, you cannot use the KeyStore class to access your PGP keys. Java 6 contains no support for PGP. You must use a third party library such as Bouncycastle's. There are two classes, PGPSecretKeyRing and PGPPublicKeyRing that are designed for processing a keyring of a single master key, and other relevant classes as well.
Harish Ponduri
Greenhorn

Joined: Jun 08, 2009
Posts: 19
Hi Greg Stark,

thank you for your reply,

Any idea in using ikeyman utility for storing my private keys.

could you please share your knowledge on ikeyman if any.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Load my private key to keystore(problem in loading private key to key store)