Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions README_RUST.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,15 @@ assert_eq!(32, key.len());

### Key Derivation

This is a method used to generate a key from a password or another key. Useful for password-dependant cryptography. Salt should be a random 16 bytes array if possible and iterations should be 10000 or configurable by the user.
Key derivation can be used to generate a key of a specific length from an input of arbitrary length such as a password.

```rust
use devolutions_crypto::utils::{generate_key, derive_key};
let key = b"this is a secret password";
let salt = generate_key(16);
let iterations = 10000;
let length = 32;

let new_key = derive_key(key, &salt, iterations, length);
use devolutions_crypto::utils::derive_key_argon2;
use devolutions_crypto::Argon2Parameters;

let key = b"this is a secret password";
let parameters = Argon2Parameters::default();
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argon2Parameters::default() generates a new random salt each time (see struct docs), so derive_key_argon2 will not be reproducible across runs unless the same parameters (especially salt) are persisted/reused. The example should either show setting a stable salt (e.g., via the builder / set_salt) or explicitly mention that callers must store/serialize the parameters to derive the same key later.

Suggested change
let parameters = Argon2Parameters::default();
// In a real application, generate a random salt once and persist/reuse the same parameters
// (including the salt) whenever you need to derive the same key again.
let mut parameters = Argon2Parameters::default();
parameters.set_salt(b"example fixed salt value");

Copilot uses AI. Check for mistakes.
let new_key = derive_key_argon2(key, &parameters).expect("default parameters should not fail");
assert_eq!(32, new_key.len());
```

Expand Down
Loading