Skip to content

java keystore

Andre Winkler edited this page May 23, 2020 · 8 revisions

KeyStore anlegen

Im ersten Schritt wird mit dem keytool ein KeyStore inklusive Zertifikat angelegt. Ich habe als Passwort awtest666 gewählt.

keytool -genkey -alias awtest -keyalg RSA -keystore awtest.jks -keysize 2048

Im zweiten Schritt das Zertifikat exportieren.

keytool -export -keystore awtest.jks -alias awtest -file awtest.cer
setExpiration() should set a Date object that is later than the Date object for the setIssuedAt().
signWith() uses the private key to sign the JWT token. This is where we should use the private key.
String jksPassword = "awtest666";

KeyStore ks  = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream("awtest.jks"), jksPassword.toCharArray());
Key key = ks.getKey("awtest", jksPassword.toCharArray());

Clone this wiki locally