Question

I have a Base-64 encoded X.509 (.CER) certificate that is causing a NullPointerException on the below java code. The line causing it is PublicKey pubKey = pubCert.getPublicKey();

Is there a way to verify that myfile.keystore has the "xyz" certificate?

final FileInputStream keyFile = new FileInputStream(filePath
                    + "myfile.keystore");
final KeyStore keyStore = KeyStore.getInstance("JKS");
String storepass = "mypass";
keyStore.load(keyFile, storepass.toCharArray());
Certificate pubCert = keyStore.getCertificate("xyz");
PublicKey pubKey = pubCert.getPublicKey();
Was it helpful?

Solution

Try the keytool command that should be in your JRE or JDK bin directory, see output below:

@raspbmc:~$ /opt/jdk1.8.0/bin/keytool  -list -help
keytool -list [OPTION]...

Lists entries in a keystore

Options:

 -rfc                            output in RFC style
 -alias <alias>                  alias name of the entry to process
 -keystore <keystore>            keystore name
 -storepass <arg>                keystore password
 -storetype <storetype>          keystore type
 -providername <providername>    provider name
 -providerclass <providerclass>  provider class name
 -providerarg <arg>              provider argument
 -providerpath <pathlist>        provider classpath
 -v                              verbose output
 -protected                      password through protected mechanism

Use "keytool -help" for all available commands

Reference:

http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/keytool.html

OTHER TIPS

Can you please confirm that the keystore is on the classpath?,

As stated above if you run keytool -list -v -keystore .jks you will see thee certificates that are installed in the keystore.

If you see you certificate in the keystore yet you are still encountering errors, it could be because the certificates are not chained correctly, I have had that issue in the past. If you are still encountering issues please paste the output from the above command and that will help us to troubleshoot your issue

Thanks

Open the keystore with tool e.g. eclipse plugin or use http://jxplorer.org/downloads/index.html

Edit this line

PublicKey pubKey = pubCert.getPublicKey();

to

PublicKey pubKey = keyStore.getPublicKey();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top