How to use the sodium-native.crypto_pwhash_async function in sodium-native

To help you get started, we’ve selected a few sodium-native 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 emilbayes / private-pipe / index.js View on Github external
function crypto_setup (cb) {
    sodium.crypto_pwhash_async(
      key,
      password,
      nonce.slice(MAGIC_BYTES.length, MAGIC_BYTES.length + sodium.crypto_pwhash_SALTBYTES),
      sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
      sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
      sodium.crypto_pwhash_ALG_DEFAULT,
      function (err) {
        if (err) return cb(err)

        instance = sodium.crypto_stream_xor_instance(nonce.slice(MAGIC_BYTES.length + sodium.crypto_passwd_SALTBYTES), key)

        cb()
      }
    )
  }
}
github fullstack-build / fullstack-one / packages / auth / dist / auth / lib / crypto.js View on Github external
return new Promise((resolve, reject) => {
        const passwordBuffer = Buffer.from(password);
        const hashBuffer = Buffer.allocUnsafe(meta.hashBytes);
        const saltBuffer = Buffer.from(meta.salt, 'hex');
        sodium.crypto_pwhash_async(hashBuffer, passwordBuffer, saltBuffer, meta.opslimit, meta.memlimit, meta.algorithm, (err) => {
            if (err != null) {
                return reject(err);
            }
            const hash = hashBuffer.toString('hex');
            resolve({
                hash,
                meta
            });
        });
    });
}
github fullstack-build / fullstack-one / packages / auth / dist / auth / lib / crypto.js View on Github external
return new Promise((resolve, reject) => {
        const passwordBuffer = Buffer.from(password);
        const hashBuffer = Buffer.allocUnsafe(config.hashBytes);
        const saltBuffer = Buffer.allocUnsafe(config.saltBytes);
        sodium.randombytes_buf(saltBuffer);
        const meta = {
            salt: saltBuffer.toString('hex'),
            hashBytes: config.hashBytes,
            opslimit: config.opslimit,
            memlimit: config.memlimit,
            algorithm: config.algorithm
        };
        sodium.crypto_pwhash_async(hashBuffer, passwordBuffer, saltBuffer, config.opslimit, config.memlimit, config.algorithm, (err) => {
            if (err != null) {
                return reject(err);
            }
            const hash = hashBuffer.toString('hex');
            resolve({
                hash,
                meta
            });
        });
    });
}
github fullstack-build / fullstack-one / packages / auth / lib / crypto.ts View on Github external
const hashBuffer = Buffer.allocUnsafe(sodiumConfig.hashBytes);

    const saltBuffer = Buffer.allocUnsafe(sodiumConfig.saltBytes);

    sodium.randombytes_buf(saltBuffer);

    const meta = {
      salt: saltBuffer.toString("hex"),
      hashBytes: sodiumConfig.hashBytes,
      opslimit: sodiumConfig.opslimit,
      memlimit: sodiumConfig.memlimit,
      algorithm: sodiumConfig.algorithm
    };

    sodium.crypto_pwhash_async(
      hashBuffer,
      passwordBuffer,
      saltBuffer,
      sodiumConfig.opslimit,
      sodiumConfig.memlimit,
      sodiumConfig.algorithm,
      (err) => {
        if (err != null) {
          return reject(err);
        }

        const hash = hashBuffer.toString("hex");

        resolve({
          hash,
          meta
github fullstack-build / fullstack-one / packages / auth / lib / crypto.ts View on Github external
return new Promise((resolve, reject) => {
    const passwordBuffer = Buffer.from(password);

    const hashBuffer = Buffer.allocUnsafe(meta.hashBytes);

    const saltBuffer = Buffer.from(meta.salt, "hex");

    sodium.crypto_pwhash_async(hashBuffer, passwordBuffer, saltBuffer, meta.opslimit, meta.memlimit, meta.algorithm, (err) => {
      if (err != null) {
        return reject(err);
      }

      const hash = hashBuffer.toString("hex");

      resolve({
        hash,
        meta
      });
    });
  });
}
github holochain / n3h / lib / mosodium / pwhash.js View on Github external
return new Promise((resolve, reject) => {
    const finalize = () => {
      password.$restoreProtection()
      hash.$restoreProtection()
    }
    try {
      password.$makeReadable()
      hash.$makeWritable()
      sodium.crypto_pwhash_async(
        hash._, password._, opts.salt,
        opts.opslimit, opts.memlimit, opts.algorithm,
        (err) => {
          try {
            finalize()
            if (err) return reject(err)
            resolve({
              salt: opts.salt,
              hash
            })
          } catch (e) {
            reject(e)
          }
        })
    } catch (e) {
      reject(e)