Base64 im Browser
// Kodieren
const encoded = btoa('Hello World');
// "SGVsbG8gV29ybGQ="
// Dekodieren
const decoded = atob('SGVsbG8gV29ybGQ=');
// "Hello World"Base64 in Node.js
const encoded = Buffer.from('Hello World').toString('base64');
const decoded = Buffer.from('SGVsbG8gV29ybGQ=', 'base64').toString('utf8');FAQ
Warum schlägt btoa() bei Sonderzeichen fehl?
btoa() akzeptiert nur Latin-1. Für Unicode TextEncoder oder encodeURIComponent verwenden.