From feb134d351915deb66feedc95bc5eeeb8c894b8e Mon Sep 17 00:00:00 2001 From: Ranieri Althoff Date: Thu, 26 Oct 2023 18:44:20 +0200 Subject: [PATCH] Use callback randomBytes for callback argon2 --- doc/api/crypto.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 9180f710a0d81f..d8c204cb4b1239 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -2905,7 +2905,7 @@ This property is deprecated. Please use `crypto.setFips()` and ### `crypto.argon2(password, salt, keylen[, options], callback)` * `password` {string|ArrayBuffer|Buffer|TypedArray|DataView} @@ -2969,23 +2969,28 @@ const { randomBytes, } = require('node:crypto'); -const salt = randomBytes(16); // Using the factory defaults. -argon2('password', salt, 64, (err, derivedKey) => { +randomBytes(16, (err, salt) => { if (err) throw err; - console.log(derivedKey.toString('hex')); // '0de3036...22afcc5' + argon2('password', salt, 64, (err, derivedKey) => { + if (err) throw err; + console.log(derivedKey.toString('hex')); // '0de3036...22afcc5' + }); }); // Using a custom iter parameter. -argon2('password', salt, 64, { iter: 3 }, (err, derivedKey) => { +randomBytes(16, (err, salt) => { if (err) throw err; - console.log(derivedKey.toString('hex')); // '0de3036...22afcc5' + argon2('password', salt, 64, { iter: 3 }, (err, derivedKey) => { + if (err) throw err; + console.log(derivedKey.toString('hex')); // '0de3036...22afcc5' + }); }); ``` ### `crypto.argon2Sync(password, salt, keylen[, options])` * `password` {string|Buffer|TypedArray|DataView}