Skip to content

Instantly share code, notes, and snippets.

@marcan2020
Created May 20, 2021 14:55
Show Gist options
  • Save marcan2020/1850ecac8d93ccd8fa4e8eadc362526f to your computer and use it in GitHub Desktop.
Save marcan2020/1850ecac8d93ccd8fa4e8eadc362526f to your computer and use it in GitHub Desktop.
shc_jws.py
import base64
def decode(data):
missing_padding = len(data) % 4
if missing_padding:
data += b'='* (4 - missing_padding)
return base64.urlsafe_b64decode(data)
jws_parts = list(map(decode, jws.split(".")))
print("header:", jws_parts[0])
# header: {"zip":"DEF","alg":"ES256","kid":"..."}
@rptaylor
Copy link

rptaylor commented Sep 7, 2021

With python 3.9.6 it seems you need data += str(b'='* (4 - missing_padding))
to avoid TypeError: can only concatenate str (not "bytes") to str

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