spring-attic/spring-cloud-security

Cannot load keys from store: class path resource [jwtkeystore.jks]

Closed this issue · 4 comments

JwtAccessTokenConverter:

@Bean  
	    public JwtAccessTokenConverter accessTokenConverter() {  
	        
	        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
            KeyPair keyPair = new KeyStoreKeyFactory(new ClassPathResource("jwtkeystore.jks"), "123456".toCharArray())
                    .getKeyPair("654321");
            converter.setKeyPair(keyPair);
            return converter;
	    }  

log:

Caused by: java.lang.IllegalStateException: Cannot load keys from store: class path resource [jwtkeystore.jks]

jwtkeystore.jks:

BOOT-INF/classes/jwtkeystore.jks   of  jar

thanks for your help

May be your maven filter has corrupted the keystore file. So, you can disable the filter.
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> </includes> <excludes> <exclude>**/*.jks</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.jks</include> </includes> <excludes> <exclude>**/*.xml</exclude> </excludes> </resource> </resources>

https://stackoverflow.com/questions/30992424/tomcat-java-io-ioexception-invalid-keystore-format-when-loading-keystore-via-cl

Closing this due to inactivity. Please re-open if there's more to discuss.

Had the same issue today in combination with docker:
When running the latest ibm-java-8 (https://hub.docker.com/r/ibmcom/ibmjava/ | 8-sfj-alpine) then I have the same Exception. When changing to an older jdk base-image (java:openjdk-8u92-jre-alpine) it works fine.

No need for me to re-open the issue here, just wanted to share my solution.

I had the same issue today.