The watch post: a note written by the real btoa. How many letters come out of its bytes, and who can read it back? An interactive Base64 playground: change…
Base64 is in image data URLs, JWTs, the Authorization: Basic header, email attachments, keys in config files. Knowing it is encoding, not encryption, stops secrets "hidden" in base64. Knowing btoa only takes Latin-1 explains InvalidCharacterError. Knowing base64url stops broken links.
Base64 is a way of writing bytes, not a lock
btoa('emoji') throws InvalidCharacterError btoa only takes Latin-1 (U+0000–U+00FF). Write its UTF-8 bytes first: btoa(String.fromCharCode(...new TextEncoder().encode(text))), and read it back with TextDecoder. Newer browsers also have Uint8Array.prototype.toBase64().atob reads it in an instant, two layers too. For a secret use real encryption (Web Crypto) and HTTPS; Authorization: Basic is only safe over HTTPS.+ / = In a query string + reads as a space, / cuts a path, = splits key from value. Use base64url (- and _, no =), or encodeURIComponent the code.= pads the end.btoa refuse a character One character above U+00FF (a long dash, a script, an emoji) and the browser throws InvalidCharacterError.TextEncoder The character becomes several UTF-8 bytes, and btoa takes them one by one.atob With no key at all. That is why base64 is no place for a secret.