Uint8Array.from和TextDecoder兼容低浏览器
const decodedData = decodeURIComponent(data) const inputString = atob(decodedData);
1、Uint8Array.from兼容低浏览器
const decryptedBytes = Uint8Array.from(inputString, c => c.charCodeAt(0)).map(byte => byte ^ 5)
对应的es5写法:
//创建一个新的 Uint8Array 并分配足够的空间来存储每个字符的 Unicode 编码
var decodedBytes = new Uint8Array(inputString.length); var decryptedBytes = []; // 遍历字符串并将每个字符的 charCodeAt 结果写入到 Uint8Array 中 for (var i = 0; i < inputString.length; i++) { decodedBytes[i] = inputString.charCodeAt(i); decryptedBytes.push(decodedBytes[i] ^ 5); }
2、TextDecoder兼容低浏览器
new TextDecoder().decode(decryptedBytes)
对应的es5写法:
decodeURIComponent(escape(String.fromCharCode.apply(null, decryptedBytes)))
浙公网安备 33010602011771号