# Password Vault

### KPasswordVault Class Overview

* **Security Parameters**\
  Uses PBKDF2 with the PBKDF2WithHmacSHA512 algorithm, a key length of 512 bits, a securely generated 32-byte salt, and an optional pepper value.
* **Hash Iteration Count**\
  If no iteration count is specified, a random value between 500,000 and 1,000,000 is used.
* **Password Verification**\
  Provides a method to validate a plaintext password by comparing it against the stored hash.

### Example

```java
public static final String SET_PASSWORD   = "SecretPassword";
public static final String TEST_PASSWORD  = "WrongPassword";
	
public static void main(String[] args) {

   KPasswordVault vault = new KPasswordVault(SET_PASSWORD.toCharArray());

   System.out.println("Hashed Password:       " + K.toHex(vault.getPasswordHash()));
   System.out.println("Used Salt:             " + K.toHex(vault.getSalt()));
   System.out.println("Used Iteration Count:  " + vault.getIterations());
   System.out.println("Hashing Elapsed Time:  " + vault.getHashTimeMs() + " ms");

   System.out.println("Validate 1st Password: " + vault.isPasswordValid(SET_PASSWORD.toCharArray()));
   System.out.println("Validate 2st Password: " + vault.isPasswordValid(TEST_PASSWORD.toCharArray()));
}
```

### Output

```
Hashed Password:       83457DACC30439A16AE5F91AE13DA176935ABEC8F7834B236A950B41A8CEE0AED8BA042DDDF5ACAB183FC0BB882E1513790DE40AA0D7FB7C8A491D8E2371CE0D
Used Salt:             52FAE4F708290D168D3DBF3D924CDAA79AD53632B897F05D3A2EE655C83B44E0
Used Iteration Count:  895434
Hashing Elapsed Time:  433 ms
Validate 1st Password: true
Validate 2st Password: false
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://java-util.k43.ch/examples/password-vault.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
