Base64 guides

Base64URL Explained

Base64URL is designed for URLs and filenames. It uses a hyphen instead of plus and an underscore instead of slash. Protocols often omit trailing equals padding.

Converting safely

Translate the alphabet only after standard encoding. Restore padding until length is divisible by four when the protocol requires it.

function toBase64Url(value){return value.replace(/\+/g,'-').replace(/\//g,'_').replace(/=+$/,'');} function addPadding(value){return value+'='.repeat((4-value.length%4)%4);}

Where it appears

JWT segments, OAuth state values, and signed links often use Base64URL. Encoding supplies no integrity or confidentiality.