Skip to content

Commit

Permalink
Use binary input for base64 decoding (more robust), more correct comment
Browse files Browse the repository at this point in the history
  • Loading branch information
hannob committed Feb 9, 2025
1 parent fb60c24 commit 915c247
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions keyfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ def makersa(n, e, d):


def ub64tobin(b64):
# convert urssafe base64 to int and fix padding first
fb64 = b64.replace(" ", "")
pad = "=" * ((-len(fb64)) % 4)
# JSON Web Keys use urlsafe base64 without padding,
# therefore, we have to fix the padding first
fb64 = b64.replace(" ", "").encode()
pad = b"=" * ((-len(fb64)) % 4)
return base64.urlsafe_b64decode(fb64 + pad)


Expand Down

0 comments on commit 915c247

Please sign in to comment.