fix btoa decoded error All In One

Posted xgqfrms

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了fix btoa decoded error All In One相关的知识,希望对你有一定的参考价值。

fix btoa decoded error All In One 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.

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.