如何在Javascript或Jquery中执行此操作?
请通过两个步骤建议:
1.-字阵列到单字节数组.
2.-字节数组到字符串.
也许这可以帮助:
function hex2a(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
Run Code Online (Sandbox Code Playgroud) 我使用crypto-js的糖度。我在下面有处理纯文本加密的功能。
import CryptoJS from 'crypto-js'
import AES from 'crypto-js/aes'
const SECRET = 'I am batman'
const plainText = 'This is Sparta!'
export function enc(plainText){
// returns something like this U2FsdGVkX184He5Rp991JYAiCSdTwfZs8T3kJUk3zAc=
// but with random `/` and I dont want that
// I want it to be Hex but .toString(CryptoJs.enc.Hex)
// is not working, it just returns an '' empty string
// it's a string, I checked using typeof
return AES.encrypt(plainText, SECRET).toString();
}
Run Code Online (Sandbox Code Playgroud)
我如何使enc(string)返回一个HexURL友好的值?