Note that there are some explanatory texts on larger screens.

plurals
  1. POnodejs crypto module vs crypto-js
    text
    copied!<p>I'm quite new to NodeJs and trying to figure out how to use the "crypto" module. While playing around with it I notice the difference between the "crypto" module in NodeJs and crypto-js: </p> <p>With crypto-js, I have: </p> <pre><code>function SHA256Hash(password, salt, iteration) { var saltedpassword = salt + password; var sha256 = CryptoJS.algo.SHA256.create(); for(var i = 0; i &lt; iteration; i++) { alert("saltedpassword = " + saltedpassword); sha256.update(saltedpassword); var saltedpassword = sha256.finalize(); sha256.reset(); } return saltedpassword.toString(CryptoJS.enc.Base64); } </code></pre> <p>Then call : </p> <pre><code>var hashedPassword = SHA256Hash("123456789", "ASIN", 3) </code></pre> <p>And receive : </p> <pre><code>saltedpassword = ASIN123456789 saltedpassword = 3362d80b757d14bfe18c01f6a003ed38a3a4a3dcab0417efb457b71740e21411 saltedpassword = 6020c992a9b7cd3ca9e95b9a3e21b64911edb7983b3dd77bdcecda19f2756987 </code></pre> <p>With "crypto" module, I wrote: </p> <pre><code>function SHA256Hash(password, salt, iteration) { var saltedpassword = salt + password; for(var i = 0; i &lt; iteration-1; i++) { console.log("saltedpassword = "+saltedpassword) var sha256 = crypto.createHash('sha256'); sha256.update(saltedpassword); var saltedpassword = sha256.digest('hex'); } console.log("saltedpassword = "+saltedpassword) var sha256 = crypto.createHash('sha256'); sha256.update(saltedpassword); return sha256.digest('base64'); } </code></pre> <p>Then call: </p> <pre><code>var hashedPassword = SHA256Hash("123456789", "ASIN", 3); </code></pre> <p>And receive:</p> <pre><code>saltedpassword = ASIN123456789 saltedpassword = 3362d80b757d14bfe18c01f6a003ed38a3a4a3dcab0417efb457b71740e21411 saltedpassword = 4795d40ae8ae797f0ce51dfe4b496bca68f6d1f4a264f4ca52348ddd65a2988d </code></pre> <p>The first two items are the same but the third item is different. Did I miss out something ?</p> <p><strong>Edited</strong>: As I compare to the Jasypt, CryptoJs generates similar keys. My question is how to tune "crypto" module to make it generate the same keys as CryptoJS and Jasypt do. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload