pub fn derive_key(
password: &[u8],
version: KeyDerivationVersion,
) -> Result<(SecretKey, DerivationParameters)>Expand description
Derives a SecretKey from password using the algorithm selected by version.
KeyDerivationVersion::LatestandKeyDerivationVersion::V2use Argon2id (recommended).KeyDerivationVersion::V1uses PBKDF2-HMAC-SHA256.
A random salt is generated automatically; the returned DerivationParameters can be
stored alongside the protected data so the same key can be reproduced later.
ยงExample
use devolutions_crypto::key_derivation::{derive_key, DerivationParameters};
use devolutions_crypto::KeyDerivationVersion;
let password = b"a very strong password";
let (secret_key, params) = derive_key(password, KeyDerivationVersion::Latest).expect("derivation should not fail");
// Serialize params to re-derive later:
let params_bytes: Vec<u8> = params.into();