ブラウザでBase64
// エンコード
const encoded = btoa('Hello World');
// "SGVsbG8gV29ybGQ="
// デコード
const decoded = atob('SGVsbG8gV29ybGQ=');
// "Hello World"Node.jsでBase64
const encoded = Buffer.from('Hello World').toString('base64');
const decoded = Buffer.from('SGVsbG8gV29ybGQ=', 'base64').toString('utf8');よくある質問
特殊文字でbtoa()が失敗するのはなぜ?
btoa()はLatin-1のみ受け付けます。Unicodeにはtextencoder或いはencodeURIComponentを使用してください。