title: How to run node crypto module with browserify
body: <p>I need to use <a href="https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback" rel="nofollow noreferrer">crypto.pbkdf2</a> on my browser.</p>
  
  <p>I use browserify to create my javascript file. The asynchronous PBKDF2 function freeze my browser entirely when iterations are larger than 1000.</p>
  
  <p><a href="https://i.stack.imgur.com/BJbVR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BJbVR.png" alt="pbkdf2 freeze"></a></p>
  
  <p><a href="http://requirebin.com/?gist=be479128d481c1ff4d5d" rel="nofollow noreferrer">RequireBin example</a></p>
  
  <pre class="lang-js prettyprint-override"><code>var crypto = require('crypto');
  var iterations = 10;
  // var iterations = 8192; // uncomment to freeze the browser
  crypto.pbkdf2('password', 'salt', iterations, 32, 'sha256', function (error, key) {
      console.log(key.toString('hex'));
  });
  </code></pre>
  
  <p><strong>How to run node crypto module with browserify ?</strong></p>
  
  <p>Edit: </p>
  
  <p>here the code created by browserify to declare pbkdf2</p>
  
  <pre class="lang-js prettyprint-override"><code>exports.pbkdf2 = pbkdf2
  function pbkdf2 (password, salt, iterations, keylen, digest, callback) {
    if (typeof digest === 'function') {
      callback = digest
      digest = undefined
    }
  
    if (typeof callback !== 'function') {
      throw new Error('No callback provided to pbkdf2')
    }
  
    var result = pbkdf2Sync(password, salt, iterations, keylen, digest)
    setTimeout(function () {
      callback(undefined, result)
    })
  }
  </code></pre>