Created
February 1, 2022 11:28
-
-
Save FrankDeGroot/3b01338eaebaca9abcaced6748560801 to your computer and use it in GitHub Desktop.
Create JWS from PEM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String readPublicKey() throws Exception { | |
val key = new String(this.getClass().getResourceAsStream("/publicKey.pem").readAllBytes()) | |
.replace("-----BEGIN PUBLIC KEY-----", "") | |
.replaceAll(System.lineSeparator(), "") | |
.replace("-----END PUBLIC KEY-----", ""); | |
val encoded = Base64.getDecoder().decode(key); | |
val keySpec = new X509EncodedKeySpec(encoded); | |
val keyFactory = KeyFactory.getInstance("RSA"); | |
val jsonWebKey = PublicJsonWebKey.Factory.newPublicJwk(keyFactory.generatePublic(keySpec)); | |
val jsonWebKeySet = new JsonWebKeySet(jsonWebKey); | |
return jsonWebKeySet.toJson(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment