Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
})
});
};
const hashPassword = (password) => sodium.crypto_pwhash_str(
password,
sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
);