/** * * * * * * */ async function sha256(message) { // 转换为ArrayBuffer const msgBuffer = new TextEncoder().encode(message); // 使用SubtleCrypto接口生成哈希 const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer); // 转换为十六进制字符串 const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); return hashHex; } function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c){ var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } const uuid=guid().replace("-","").replace("-","").replace("-","").replace("-",""); // "a1ca0f7b-51bd-4bf3-a5d5-6a74f6adc1c7"; sessionStorage.setItem("bsf", 'asdfghjklzxcvbnmqwertyuiopASDFGHJKLZXCVBNMQWERTYUIOP1234567890') // let bsff = 'asdfghjklzxcvbnmqwertyuiopASDFGHJKLZXCVBNMQWERTYUIOP1234567890' const timeStamp = new Date().getTime(); function formatTimestamp(timestamp) { const date = new Date(timestamp); const year = date.getFullYear(); const month = ('0' + (date.getMonth() + 1)).slice(-2); const day = ('0' + date.getDate()).slice(-2); // const hours = ('0' + date.getHours()).slice(-2); // const minutes = ('0' + date.getMinutes()).slice(-2); // const seconds = ('0' + date.getSeconds()).slice(-2); // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; return `${year}-${month}-${day}`; } const yeeDate = formatTimestamp(timeStamp) function removeInvalidUtf8Chars(input) { // 正则表达式匹配不符合 UTF-8 的字符 // 0xC0-0xC1, 0xF5-0xFF 是 UTF-8 编码中不合法的字节 // 0x80-0xBF, 0xC2-0xF4 跟随的字节如果不符合规范,也会被认为是非法的 const invalidUtf8Regex = /[\xC0-\xC1]|[\xF5-\xFF]|[\x80-\xBF]|([\xC2-\xF4][^\x80-\xBF])/g; // 使用正则表达式替换不符合的字符为空字符串 return input.replace(invalidUtf8Regex, ''); } var Base64 = { // let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode:function(e) { // function bsencodeURI(e){ var t = ""; var n, r, i, s, o, u, a; var f = 0; // e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t += this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) // t += _keyStr.charAt(s) + _keyStr.charAt(o) + _keyStr.charAt(u) + _keyStr.charAt(a) } return t }, // } decode:function(e) { // function bsdecode(e){ // console.log("e", e, e.length) var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace('/[^A-Za-z0-9+/=]/g', "").toString() // console.log("e", e, e.length) while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); // console.log("s o u a", s, o, u, a) n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t += String.fromCharCode(r) } if (a != 64) { t += String.fromCharCode(i) } } // t = Base64._utf8_decode(t); // console.log('t',t) return t }, // } _utf8_encode: function(e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }