【问题标题】:What kind of data does crypto-js function return?crypto-js 函数返回什么样的数据?
【发布时间】:2014-11-02 05:16:41
【问题描述】:

我正在使用 crypto-js 使用 PBKDF2 加密密码,以将密钥传递给 AES 加密函数。

var PBKDF2hash = crypto.PBKDF2(req.body.password, salt, { keySize: 256/32 });

当我使用 crypto-js 哈希函数时,console.log(PBKDF2hash) 在控制台中返回这个奇怪的数据:

    { init: [Function],
  '$super': 
   { init: [Function],
     toString: [Function],
     concat: [Function],
     clamp: [Function],
     clone: [Function],
     random: [Function],
     '$super': 
      { extend: [Function],
        create: [Function],
        init: [Function],
        mixIn: [Function],
        clone: [Function] } },
  words: 
   [ 162340080,
     -1329278032,
     -946859974,
     1516294488,
     -1059418968,
     60522350,
     440072457,
     -2049460689,
     -571434654,
     1087160278 ],
  sigBytes: 32 }

这是什么数据?函数不应该以字符串的形式返回通常的散列密码吗?

【问题讨论】:

    标签: javascript node.js encryption cryptojs pbkdf2


    【解决方案1】:

    来自the documentation

    您返回的哈希还不是字符串。它是一个 WordArray 对象。在字符串上下文中使用 WordArray 对象时,它会自动转换为十六进制字符串。

    您可以通过显式调用 toString 方法并传递编码器来将 WordArray 对象转换为其他格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-16
      相关资源
      最近更新 更多