title: Spring Boot JWT - JKS file and Public key
body: <p>I'm executing this steps using <strong>Java keytool</strong> and <strong>OpenSSL</strong> to create JKS file and public key. Using <strong>Spring Boot</strong> <strong>Authorization server</strong> is going to use <strong>JKS file</strong> to create a <strong>JWT token</strong> and <strong>Resource server</strong> is going to use <strong>public key</strong> to verify JWT token.</p>
  
  <p>1 First I create the JKS file like this: <br/>
  <code>keytool -genkeypair -alias authentication-server -keyalg RSA -dname "CN=GC,OU=DC,O=BatmanCorp,L=GT,C=Gotham" -keystore auth-server.jks -keypass batman20; -storepass bruce20; -validity 180 -keysize 2048</code></p>
  
  <p>Then with the following command I print in console the public key: <br/>
  <code>keytool -list -rfc --keystore auth-server.jks | openssl x509 -inform pem -pubkey -noout</code></p>
  
  <p>Using the above command, most of the time the last lines printed are not in the correct order, but this is the simple way to get both files (JKS file and public key).</p>
  
  <p>I found another way with more steps, after create JKS file, I execute following steps (maybe this steps are irrelevant, but can be useful for someone's else).</p>
  
  <p>2 Create P12 file <br/>
  <code>keytool -importkeystore -srckeystore auth-server.jks -srcstorepass bruce20; -srckeypass batman20; -srcalias authentication-server -destalias authentication-server -destkeystore auth-server.p12 -deststoretype PKCS12 -deststorepass batman_20; -destkeypass batman_20;</code></p>
  
  <p>3 Create PEM file <br/>
  <code>openssl pkcs12 -in auth-server.p12 -nodes -nocerts -out auth-server-private-key.pem</code></p>
  
  <p>4 Create Pub file <br/>
  <code>openssl rsa -in auth-server-private-key.pem -pubout -out PublicKey.pub</code></p>
  
  <p>In all the steps I'm using simple passwords and dummy data, in real projects I use more complex passwords.</p>
  
  <p><strong>Here are my questions:</strong></p>
  
  <p>In first step, is possible to improve it to increase the security level?<br/>
  Is there another way to create both files with a better security level?</p>