Solving java.io.IOException: Invalid secret key format
This issue happens when a Java module is unable to access com.sun.crypto libraries earlier than its Classloader modules. You will typically see a Stack trace which looks like this:
Caused by: java.io.IOException: Invalid secret key format
at com.sun.crypto.provider.JceKeyStore.engineLoad(JceKeyStore.java:856)
at java.security.KeyStore.load(Unknown Source)
at org.picketbox.util.KeyStoreUtil.getKeyStore(KeyStoreUtil.java:201)
at org.picketbox.util.KeyStoreUtil.getKeyStore(KeyStoreUtil.java:151)
at org.picketbox.plugins.vault.PicketBoxSecurityVault.getKeyStore(PicketBoxSecurityVault.java:688)
One way to solve this issue is to upgrade the keystore from JCEKS to PKCS12. As the JCEKS keystore uses a proprietary format is it subject to changes for example if you update your JDK.
You can use the keytool command line to migrate a keystore from JCEKS to PKCS12:
keytool -importkeystore -srckeystore [KEYSTORE.jks] -destkeystore [FILE.p12] -srcstoretype JKS - deststoretype PKCS12 -deststorepass [PASSWORD_PKCS12]
If your application requires using a JCEKS keystore, then you have to force early access to the sun.jdk libraries.
If you are using WildFly application server, then you can add into the specific module.xml file (for example the one of “org.picketbox” module) a dependency to “sun.jdk” module:
<module name="sun.jdk"/>
Also, if you want to add visibility to the “com.sun” packages to all WildFly modules, then in your configuration script (standalone.conf), add to the JBOSS_MODULES_SYSTEM_PKGS also the “com.sun.crypto.provider” package as follows:
if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,com.sun.crypto.provider" fi
Recommended Articles
Fixing the Jenkins SSLHandshakeException with a Valid JDK Certificate
Learn how to solve the common issue of the Jenkins SSL Handshake Exception caused by a missing or invalid certificate in your JDK. Get step-by-step instructions for resolving this error and ensuring secure plugin installation.
Create a Custom Elytron Realm in WildFly 31: A Step-by-Step Guide
Learn how to create a custom realm in Elytron, a modern replacement for legacy Login Modules, with this comprehensive tutorial. Get started with creating a custom realm using WildFly 31 and configuring it to store user credentials.
Secure Your Datasource Passwords in WildFly Using Elytron Credential Stores
Learn how to secure your datasource passwords in WildFly with Elytron credential stores and JCEKS keystore files. #WildFly #Java #Security #Middleware
Solving SSLHandshakeException in Java Applications: A Comprehensive Guide
Learn how to resolve SSLHandshakeException in Java applications using WildFly, Spring Boot, Quarkus, or microservices with modern TLS standards.