How to use the libsodium-wrappers-sumo.crypto_pwhash_SALTBYTES 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
sodium.ready.then(() => {
      if (!this.initPwd) {
        // Get salt from stream to re-generate key
        if (!this.pwdHeader) {
          this.pwdHeader = Buffer.alloc(sodium.crypto_pwhash_SALTBYTES + 1);
        }

        if (!this.key) {
          const saltBytesCopied = data.copy(this.pwdHeader, this.pwdHeaderOffset);
          this.pwdHeaderOffset += saltBytesCopied;

          if (this.pwdHeaderOffset < sodium.crypto_pwhash_SALTBYTES) {
            return callback(null, null);
          }
          if (this.pwdHeader[0] !== PWD_STREAM_VERSION) {
            return callback(new Error('Unsupported PwdEncryptionStream version'));
          }

          this.key = sodium.crypto_pwhash(
            KEY_SIZE,
            this.pwd,
            this.pwdHeader.slice(1),
            sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
            sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
            sodium.crypto_pwhash_ALG_DEFAULT
          );
          this.initPwd = true;
          data = data.slice(saltBytesCopied);
github Cryptonomic / ConseilJS / src / utils / WrapperWrapper.js View on Github external
const salt = async () => {
    return rand(sodiumsumo.crypto_pwhash_SALTBYTES);
}
github auth0 / magic / magic.js View on Github external
return sodium.ready.then(() => {
    if (typeof p === 'function') {
      cb = p;
      p = null;
    }
    const done = ret(cb);

    if (!p) { return done(new Error('Cannot decrypt without a password')); }

    let s, salt;
    [ c ] = cparse(c);
    salt = c.slice(0, sodium.crypto_pwhash_SALTBYTES);
    try {
      s = 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));
    }
    c = c.slice(sodium.crypto_pwhash_SALTBYTES);
    return dsync(s, c, n, cb);
  })
};
github auth0 / magic / magic.js View on Github external
return sodium.ready.then(() => {
    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);
github auth0 / magic / magic.js View on Github external
let s, salt;
    [ c ] = cparse(c);
    salt = c.slice(0, sodium.crypto_pwhash_SALTBYTES);
    try {
      s = 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));
    }
    c = c.slice(sodium.crypto_pwhash_SALTBYTES);
    return dsync(s, c, n, cb);
  })
};