我正在尝试使用CryptoJS将数据编码为Base64。我的代码如下:
let key = "test";
let iv = myCrypto.lib.WordArray.random(16);
let newKey = myCrypto.PBKDF2(key, iv, {keySize: 128/32});
let encrypted = myCrypto.AES.encrypt("hello", newKey, {iv: iv});
let ivString = myCrypto.enc.Base64.stringify(iv);
let decoded = myCrypto.enc.Base64.parse(ivString);当我打印解码后,我得到以下输出:
{ init: [Function],
'$super':
{ init: [Function],
toString: [Function: toString],
concat: [Function: concat],
clamp: [Function: clamp],
clone: [Function: clone],
random: [Function: random],
'$super':
{ extend: [Function: extend],
create: [Function: create],
init: [Function: init],
mixIn: [Function: mixIn],
clone: [Function: clone] } },
words: [ -1828772172, 1815131715, 749929333, 1399144403 ],
sigBytes: 16 }如果我尝试使用十六进制编码,我会得到预期的输出。
这是CryptoJS库的问题吗?如果没有,我该如何解决这个问题?
发布于 2018-08-23 22:34:09
解码由随机字节组成,这些字节似乎是延迟生成的(即,当需要它们时)。只是打印字节-根据定义-不会产生任何有用的结果,因为字节具有随机值。JavaScript支持有点棘手,因为JavaScript没有使用字节作为基元类型(因此使用了字数组)。
要查看字节,首先将其编码为十六进制,然后打印它们。
https://stackoverflow.com/questions/51955580
复制相似问题