Skip to content

Instantly share code, notes, and snippets.

@phi1ipp
Last active June 22, 2023 17:33
Show Gist options
  • Save phi1ipp/2b0985b2f39bd7ff341843d03e994e98 to your computer and use it in GitHub Desktop.
Save phi1ipp/2b0985b2f39bd7ff341843d03e994e98 to your computer and use it in GitHub Desktop.

Revisions

  1. phi1ipp revised this gist Jun 22, 2023. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion pem2jwk.sh
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ openssl rsa -in priv.pem -pubout > pub.pem
    n=$(openssl rsa -pubin -in pub.pem -noout -modulus | cut -f2 -d= | xxd -r -p | base64 | sed -e 's/\//_/g' -e 's/+/-/g' -e 's/=//g')

    # encode exponent
    e=$()
    # standard one is 65537
    e="AQAB"

    kty="RSA"
  2. phi1ipp created this gist Jun 22, 2023.
    11 changes: 11 additions & 0 deletions pem2jwk.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # generate RSA
    openssl genrsa 4096 > priv.pem
    openssl rsa -in priv.pem -pubout > pub.pem

    # encode modulus
    n=$(openssl rsa -pubin -in pub.pem -noout -modulus | cut -f2 -d= | xxd -r -p | base64 | sed -e 's/\//_/g' -e 's/+/-/g' -e 's/=//g')

    # encode exponent
    e=$()

    kty="RSA"