user3081123
user3081123

Reputation: 435

What kind of data does crypto-js function return?

I am using crypto-js to encrypt a password with PBKDF2 to pass a key to AES encryption function.

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

When I use crypto-js hash functions, console.log(PBKDF2hash) returns this weird data in console:

    { 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 }

What kind of data is this? Isn't function supposed to return a usual hashed password in form of a string?

Upvotes: 2

Views: 995

Answers (1)

Quentin
Quentin

Reputation: 944196

From the documentation:

The hash you get back isn't a string yet. It's a WordArray object. When you use a WordArray object in a string context, it's automatically converted to a hex string.

and

You can convert a WordArray object to other formats by explicitly calling the toString method and passing an encoder.

Upvotes: 4

Related Questions