mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
1.3 KiB
1.3 KiB
Password-based key derivation
See also: Libsodium's documentation on Argon2.
crypto_pwhash
Derive a cryptography key from a password and salt.
Parameters and their respective types:
{number}output length{string|Buffer}password{Buffer}salt (16 bytes){number}opslimit (recommeded minimum:2){number}memlimit (recommended mimimum:67108864a.k.a. 64MiB){number|null}algorithm (recommended:this.CRYPTO_PWHASH_ALG_DEFAULT)
Returns a Promise that resolves to a CryptographyKey.
Example for crypto_pwhash
This example is for key derivation. Look below for information about password storage/verification.
const { SodiumPlus } = require('sodium-plus');
let sodium;
(async function () {
if (!sodium) sodium = await SodiumPlus.auto();
let password = 'correct horse battery staple';
let salt = await sodium.randombytes_buf(16);
let key = await sodium.crypto_pwhash(
32,
password,
salt,
sodium.CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
sodium.CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
);
console.log(key.getBuffer().toString('hex'));
})();