Java Keystore Files
Create a Java Keystore (.JKS) from Let's Encrypt Certificates
Application server like Jetty, Glassfish or Tomcat need a keystore (.jks) in order to properly handling the certificates. These three simple steps will create a valid keystore file for your application server using the Let's Encrypt service. Have fun, be encrypted!
Step 1 - Create keys
Skip if you already have a cert
./letsencrypt-auto certonly --standalone -d DOMAIN.TLD -d DOMAIN_2.TLD --email EMAIL@EMAIL.TLD
Change to the directory (probably /etc/letsencrypt/live/DOMAIN.tld) where the certificates were created.
Step 2 - Create a PKCS12 file containing full chain and private key
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out pkcs.p12 -name NAME
Step 3 - Convert PKCS12 to Keystore
The STORE_PASS is the password which was entered in step 2) as a password for the pkcs12 file.
keytool -importkeystore -deststorepass PASSWORD_STORE -destkeypass PASSWORD_KEYPASS -destkeystore keystore.jks -srckeystore pkcs.p12 -srcstoretype PKCS12 -srcstorepass STORE_PASS -alias NAME
If you happen to get a java.io.IOException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded
, you have probably forgotten to enter the correct password from step 2.
The commands
sudo openssl pkcs12 -export -in /opt/bot-jens/fullchain.pem -inkey /opt/bot-jens/privkey.pem -out pkcs.p12 -name panel.bot.jensz12.com
sudo keytool -importkeystore -deststorepass PASSWORD -destkeystore keystore.jks -srckeystore pkcs.p12 -srcstoretype PKCS12 -srcstorepass PASSWORD -alias panel.bot.jensz12.com