Last active
March 25, 2021 15:12
-
-
Save seva-ramin/0735c55b4d293f44ff50c18df130ee40 to your computer and use it in GitHub Desktop.
JWT Decoder using bash
This file contains hidden or 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
#!/bin/bash | |
# pad base64URL encoded to base64 | |
paddit() { | |
input=$1 | |
l=`echo -n $input | wc -c` | |
while [ `expr $l % 4` -ne 0 ] | |
do | |
input="${input}=" | |
l=`echo -n $input | wc -c` | |
done | |
echo $input | |
} | |
# read and split the token and do some base64URL translation | |
read jwt | |
read h p s <<< $(echo $jwt | tr [-_] [+/] | sed 's/\./ /g') | |
h=`paddit $h` | |
p=`paddit $p` | |
# assuming we have jq installed | |
echo $h | base64 -d | jq | |
echo $p | base64 -d | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment