2

I have created a key store and extracted the public key. In order to use key store I've created a keyproperties.properties file, but I'm not sure about the property called "PRIVATE". I'm totally confused whether that is a path or private key password or something else.

  1. properties file -> with .properties extension
  2. data is not coming from anywhere and I'm using static data.
  3. PRIVATE-> path of keystore which is used to get private key

This is a snippet of my code:

public static void main(String[] args)throws Exception {
   Properties properties = new Properties();
   String path = properties.getProperty("PRIVATE");
   KeyStore ks = KeyStore.getInstance("pkcs12", "BC");
   ks.load(new FileInputStream(path), keystore_password.toCharArray());
}
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
kerZy Hart
  • 181
  • 4
  • 17
  • How did you create your properties file? Where the data comes from? What about doing a stupid 'System.out.println' of the property 'PRIVATE'? – Algiz Aug 19 '13 at 07:37

1 Answers1

3

When you create a Properties object using new Properties(), you don't have any data stored in that object yet. So it doesn't make sense to do properties.getProperty("PRIVATE") because that will always return null.

You claim that you've made a .properties file, but I don't see you loading into the Properties object anywhere:

properties.load(new FileInputStream(readerForProperties));

Whichever properties you've defined in the .properties file (see API documentation to find out how to create such a file) using a Reader that can read that file, will now be accessible using the getProperty() method.

You are using the path variable to create a FileInputStream that is used to load a KeyStore. In that case, path needs to be the path to your key store.

It seems as if you copy/pasted an example I've written without reading (or at least: without understanding) the documentation.

In my example, I used "Private" as property name, but that's irrelevant. If you prefer naming it "pathToKS" or "keystore" or even "banana", you can do so.

In my case, my .properties file looks like this:

PUBLIC      c:/examples/signatures/public.cer
ROOTCERT    c:/examples/signatures/CACertSigningAuthority.crt
PRIVATE     c:/examples/signatures/private.p12
PASSWORD    secret

So in my case, properties.getProperty("PRIVATE") will return my keystore, properties.getProperty("PUBLIC") will return my public key, properties.getProperty("ROOTCERT") will return the public key of a Certificate Authority and properties.getProperty("PASSWORD") will return my password for the keystore and for the private key stored in the keystore corresponding with my public key (these password needn't be identical).

If you prefer to store your path to the keystore like this:

banana  c:/examples/signatures/private.p12

You'll need to do this:

String path = properties.getProperty("banana");

Please read the documentation carefully before writing more code. Reading the documentation will save you plenty of time.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Thank you very much for your wonderful reply.i have generated a digitally signed pdf document using iText 5.3.4.and i have one more doubt.what are all the versions of iText used to generate digital Signature? – kerZy Hart Aug 22 '13 at 02:50
  • 5.3.4 was one of the versions released during the development of the new functionality. Some parts of the signing functionality were still under development at the time that release was made. And also: there was a bug in the BC version back then; in the meantime BC was updated. – Bruno Lowagie Aug 22 '13 at 07:08
  • Hi bruno i have posted a question on the following page http://stackoverflow.com/questions/19441977/how-to-read-or-extract-graphical-componenets-such-as-square-rect-line-etc-fro. Please give me suggestion,and it would be greatful – kerZy Hart Oct 18 '13 at 05:11