简体   繁体   中英

How to load a keystore, which is inside the resource folder (maven)?

I have a custom SSL factory, where I load my own truststore.

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

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

But I want my truststore inside my resource folder, which was built with maven where the path is src/main/resources .

Then I do and it doesn't work with the following line:

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

Though the input stream exists. I checked it. It only fails when I do ks.load(...).

The exception that I get is:

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

Why is that?

Regards, Dave

Strange, it works now...

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");

Anyone knows why? Is this solution ok?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM