SSL Java java.io.IOException: Invalid keystore format

后端 未结 5 855
忘掉有多难
忘掉有多难 2020-12-15 23:08

I am testing SSL in java with SSLServerSocket and other classes in the java.ssl package. When I run the following code, I get the exception java.io.IOException: Invalid keys

5条回答
  •  盖世英雄少女心
    2020-12-16 00:03

    I had exactly the same issue. Indeed, the keystore file was invalid and not related to the JDK//JRE version. The problem in my case was caused by Maven. I was using the following option in my pom file:

    
            
                src/main/resources
                true
            
        
    

    The "true" value in the filtering was messing with the key file. Therefore, the keyfile that was available in my classpath when Spring run was not exactly the same I had under my directory "src/main/resources" and that caused the Invalid Keystore Format exception. When I tested with keytool I was using the one under the "resources" folder so that was misleading the real issue.

    Solving the issue: in your pom.xml file, change the value for "filtering" to "false". Another way of solving the issue was to specify explicitly the location of the keystore in the application.properties file. So instead of:

    server.ssl.key-store: classpath:keystore.jks
    

    I used

    server.ssl.key-store: keystore/keystore.jks
    

提交回复
热议问题