Last active
March 21, 2021 22:27
-
-
Save lilian-benoit/3c9696ed69d67ad0b1ccefbfe859e4e9 to your computer and use it in GitHub Desktop.
Récupérer le certificat public au format PEM à partir d'un JWKS
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
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS info.picocli:picocli:4.5.0 | |
//DEPS org.bitbucket.b_c:jose4j:0.7.6 | |
import picocli.CommandLine; | |
import picocli.CommandLine.Command; | |
import picocli.CommandLine.Parameters; | |
import java.util.List; | |
import java.util.concurrent.Callable; | |
import org.jose4j.jwk.HttpsJwks; | |
import org.jose4j.jwk.JsonWebKey; | |
import org.jose4j.keys.RsaKeyUtil; | |
@Command(name = "GetKey", mixinStandardHelpOptions = true, version = "GetKey 0.1", | |
description = "GetKey made with jbang") | |
class GetKey implements Callable<Integer> { | |
@Parameters(index = "0", description = "URL vers JSON Web Key Sets (JWKS)") | |
private String url; | |
public static void main(String... args) { | |
int exitCode = new CommandLine(new GetKey()).execute(args); | |
System.exit(exitCode); | |
} | |
@Override | |
public Integer call() throws Exception { | |
HttpsJwks jwks = new HttpsJwks(url); | |
List<JsonWebKey> liste = jwks.getJsonWebKeys(); | |
for (JsonWebKey jsonWebKey : liste) { | |
String cert = RsaKeyUtil.pemEncode(jsonWebKey.getPublicKey()); | |
System.out.println(cert); | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment