fix btoa decoded error All In One
base64 encode / decode
Uncaught DOMException: Failed to execute 'atob' on 'Window': The string
to be decoded
contains characters
outside of the Latin1
range.
Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
error
let s = `此密码只会在此设备上解锁您的 MetaMask 钱包。MetaMask 无法恢复此密码。`;
atob(s)
// Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded contains characters outside of the Latin1 range.
btoa(s)
// Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
solution
btoa(unescape(encodeURIComponent(s)));
// '5q2k5a+G56CB5Y+q5Lya5Zyo5q2k6K6+5aSH5LiK6Kej6ZSB5oKo55qEIE1ldGFNYXNrIOmSseWMheOAgk1ldGFNYXNrIOaXoOazleaBouWkjeatpOWvhueggeOAgg=='
atob(unescape(encodeURIComponent(s)));
// Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.