aspose file tools*
The moose likes Security and the fly likes Bouncy Castle : Public Key Retrieval based on the finger print provided Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Bouncy Castle : Public Key Retrieval based on the finger print provided" Watch "Bouncy Castle : Public Key Retrieval based on the finger print provided" New topic
Author

Bouncy Castle : Public Key Retrieval based on the finger print provided

Rakesh Megharaj
Greenhorn

Joined: Dec 13, 2012
Posts: 12
Is there any way to retrieve the public key based on the fingerprint from the collection file (i.e. the .gpg file) using the Bouncy Castle Api (bcprov-jdk15on-147.jar). As i want to move my application using GNUPG tool to Bouncy castle, where the collection and the finger print is provided for the encryption of a file.As encryption in the BC can be achieved through public key.It would be of great help if you could provide some example.

Is .gpg in GNUPG equivalent for both .pkr and .skr files?
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1067
    
  10

Just load the file into a PGPPublicKeyRingCollection and then iterate though each contained keyring until you find the key with the matching fingerprint! One of the BC PGP examples has 90% of the code you require for doing this!

As far as "Is .gpg in GNUPG equivalent for both .pkr and .skr files" is concerned then I'm not sure what you mean by 'equivalent' . As far as I remember the pubring.gpg file has the same format as a '.pkr' file and the secring.gpg file has the same format as a '.skr' file but you can't use the same Java BC code to load both. If you look at the BC examples and Javadoc you will be able to extrapolate from loading the public key file to loading the private key file.

Since this project sounds like it has a large number of PGP key I'm surprise you are not using a database to hold the public keys. I use a MySQL database for public keys with an index on the email address, the fingerprint and the customer name.
Rakesh Megharaj
Greenhorn

Joined: Dec 13, 2012
Posts: 12
Thanks for the quick reply.
I will try this one.
We are using the Database to store the PGPKeys.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Bouncy Castle : Public Key Retrieval based on the finger print provided