Base64URL drops the '=' padding: how to strip and restore it without breaking tokens
Tokens encoded in standard Base64 often fail when placed in URLs, because '+' turns into a space, '/' can break routing, and '=' gets percent-encoded. Base64URL solves this by swapping '+' and '/' for '-' and '_', as defined in RFC 4648. Omitting the trailing '=' is allowed when the data length is known, and JWT (RFC 7515) requires it. The padding can be restored by computing the remainder of the length divided by 4, adding two or one '=' accordingly, while a remainder of 1 signals a truncated or corrupted string. The article illustrates this with Python and Node.js examples that handle padding correctly.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in