fix btoa decoded error All In One

发布时间 2023-03-23 02:59:59作者: xgqfrms

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.

image

(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

btoa()

The btoa() method creates a Base64-encoded ASCII string from a binary string (i.e., a string in which each character in the string is treated as a byte of binary data).

https://developer.mozilla.org/en-US/docs/Web/API/btoa

atob()

The atob() function decodes a string of data which has been encoded using Base64 encoding. You can use the btoa() method to encode and transmit data which may otherwise cause communication problems, then transmit it and use the atob() method to decode the data again. For example, you can encode, transmit, and decode control characters such as ASCII values 0 through 31.

https://developer.mozilla.org/en-US/docs/Web/API/atob

refs

https://stackoverflow.com/questions/23223718/failed-to-execute-btoa-on-window-the-string-to-be-encoded-contains-characte



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!