下面是Crypto-JS照搬过来的,不过在node.js下貌似会不行
function util_bytesToBase64(a) {
if ("function" == typeof btoa) return btoa(f_bytesToString(a));
for (var b = [], c = 0; c < a.length; c += 3) for (var d = a[c] << 16 | a[c + 1] << 8 | a[c + 2], e = 0; 4 > e; e++) 8 * c + 6 * e <= 8 * a.length ? b.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d >>> 6 * (3 - e) & 63)) : b.push("=");
return b.join("");
}
function util_hexToBytes(a) {
for (var b = [], c = 0; c < a.length; c += 2) b.push(parseInt(a.substr(c, 2), 16));
return b;
}
function util_bytesToHex(a) {
for (var b = [], c = 0; c < a.length; c++) b.push((a[c] >>> 4).toString(16)),
b.push((a[c] & 15).toString(16));
return b.join("");
}
function charenc_UTF8_bytesToString(a){
return decodeURIComponent(escape(f_bytesToString(a)));
}
function charenc_UTF8_stringToBytes(a) {
return f_stringToBytes(unescape(encodeURIComponent(a)));
}
function f_stringToBytes(a) {
for (var b = [], c = 0; c < a.length; c++) b.push(a.charCodeAt(c) & 255);
return b;
}
function f_bytesToString(a) {
for (var b = [], c = 0; c < a.length; c++) b.push(String.fromCharCode(a[c]));
return b.join("");
}
function util_base64ToBytes(a) {
if ("function" == typeof atob) return f_stringToBytes(atob(a));
for (var a = a.replace(/[^A-Z0-9+\/]/ig, ""), b = [], c = 0, d = 0; c < a.length; d = ++c % 4) 0 != d && b.push(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(c - 1)) & Math.pow(2, -2 * d + 8) - 1) << 2 * d | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(c)) >>> 6 - 2 * d);
return b;
}
报错:
SyntaxError: Unexpected token ) at Module.wrappedCompile [as _compile] (instance1/nodejs/runtime/src/sandbox/modules/module.js:104:24) at Object.Module._extensions..js (module.js:502:10) at Module.load (module.js:392:32) at Function.Module._load (module.js:350:12) at Module.require (module.js:398:17) at require (instance1/nodejs/runtime/src/sandbox/modules/module.js:42:15) at Object. (instance1/nodejs/test/app/routes/index.js:1:74) at Module.wrappedCompile [as _compile] (instance1/nodejs/runtime/src/sandbox/modules/module.js:118:25) at Object.Module._extensions..js (module.js:502:10) at Module.load (module.js:392:32)
新人不知道怎么解决好。无限感谢