How to use the libsodium-wrappers-sumo.crypto_pwhash_OPSLIMIT_INTERACTIVE function in libsodium-wrappers-sumo

To help you get started, we’ve selected a few libsodium-wrappers-sumo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github auth0 / magic / magic.js View on Github external
function pw(password, cb) {
  const done = ret(cb);

  if (!password) { return done(new Error('Empty password')); }

  let hash;
  try {
    // generates the salt itself
    hash = sodium.crypto_pwhash_str(password, sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE);
  } catch(ex) {
    return done(new Error('Libsodium error: ' + ex));
  }

  return done(null, convert({
    alg:  'argon2id',
    hash: hash
  }));
}
github TankerHQ / quickstart-examples / server / src / auth.js View on Github external
const hashPassword = (password) => sodium.crypto_pwhash_str(
  password,
  sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
  sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
);
github auth0 / magic / magic.js View on Github external
if (typeof p === 'function') {
      cb = p;
      p = null;
    }
    const done = ret(cb);

    if (!p) { return done(new Error('Cannot encrypt without a password')); }
    let sk;
    const salt = crypto.randomBytes(sodium.crypto_pwhash_SALTBYTES)

    try {
      sk = sodium.crypto_pwhash(
        KEY_SIZE,
        p,
        salt,
        sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
        sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
        sodium.crypto_pwhash_ALG_DEFAULT
      );
    } catch(ex) {
      return done(new Error('Libsodium error: ' +  ex))
    }

    return sync(m, Buffer.from(sk), (err, aead) => {
      const done = ret(cb);
      if (err) {
        return err;
      }
      aead.ciphertext = Buffer.concat([salt, aead.ciphertext])
      return done(null, aead);
    })
  });