How to load the keystore that is inside the resource folder (maven)?

I have my own SSL factory where I load my own private store.

Now, when I put the truststore.jks file in the root folder of the project, it works with the following line:

ks.load(new FileInputStream("/truststore.jks", passphrase); 

But I want my trust store to be inside my resources folder, which was built using maven, where the path is src / main / resources .

Then I do this and it does not work with the following line:

 ks.load(this.getClass().getResourcesAsStream("/truststore.jks"), passphrase); 

Although the input stream exists. I checked it out. This only happens when ks.load (...) is executed.

Exception I get:

  java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty 

Why is this?

Regards, Dave

+6
source share
1 answer

Strange, now it works ...

I had

 Properties systemProps = System.getProperties(); systemProps.put( "javax.net.ssl.trustStore", "/truststore.jks"); systemProps.put( "javax.net.ssl.trustStorePassword", "changeit"); System.setProperties(systemProps); 

and change the second line to

 systemProps.put( "javax.net.ssl.trustStore", "src/main/resources/truststore.jks"); 

Does anyone know why? Is this solution ok?

-1
source

All Articles