Skip to content

Instantly share code, notes, and snippets.

@jkroepke
Last active September 29, 2022 11:12
Show Gist options
  • Save jkroepke/0b6edb588aa6dcff5b392e7350359e21 to your computer and use it in GitHub Desktop.
Save jkroepke/0b6edb588aa6dcff5b392e7350359e21 to your computer and use it in GitHub Desktop.
JWKS to PEM in bash
#!/usr/bin/env sh
set -euo pipefail
JWKS_TEMP=$(mktemp)
JWKS_URL=$1
curl -s "${JWKS_URL}" | \
python -c 'import sys, json; data=json.load(sys.stdin); print(data["keys"][0]["n"] + data["keys"][0]["e"])' > "${JWKS_TEMP}"
{
echo 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA' | openssl base64 -d;
head -c 256 "${JWKS_TEMP}";
printf '\2\3';
tail -c+258 "${JWKS_TEMP}" | head -c 3
} | openssl pkey -inform der -outform pem -pubin
@StepanKuksenko
Copy link

doesn't work for me
i got different result then here https://8gwifi.org/jwkconvertfunctions.jsp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment