首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CryptoJS解码返回值

CryptoJS解码返回值
EN

Stack Overflow用户
提问于 2018-08-22 03:37:28
回答 1查看 88关注 0票数 0

我正在尝试使用CryptoJS将数据编码为Base64。我的代码如下:

代码语言:javascript
复制
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);

当我打印解码后,我得到以下输出:

代码语言:javascript
复制
{ 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库的问题吗?如果没有,我该如何解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2018-08-23 22:34:09

解码由随机字节组成,这些字节似乎是延迟生成的(即,当需要它们时)。只是打印字节-根据定义-不会产生任何有用的结果,因为字节具有随机值。JavaScript支持有点棘手,因为JavaScript没有使用字节作为基元类型(因此使用了字数组)。

要查看字节,首先将其编码为十六进制,然后打印它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51955580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档