🔨
Java Utility Package
🔨
Java Utility Package
  • Java Utility Package (Open Source)
  • Examples
    • 📖Logging
    • 🔧Utility Class
    • 🔑Password Vault
    • 🖥️HTTP / Socket Server
    • ⚒️HTTP Client
    • 🖥️Socket Client
    • 🗃️JDBC Database
    • ✉️SMTP Mailer
    • ⚔️Java Thread
    • 🗄️File Tools
    • ⌚Timer
    • 💡Tips / FAQ
  • Downloads
    • ⬇️Package ch.k43.util
    • ⬇️Sample Code
    • 📖JavaDoc API
    • 👨‍💻GitHub
Powered by GitBook
  1. Examples

Password Vault

Securely hash, store and verify passwords.

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

public static final String SET_PASSWORD       = "SecretPassword";
public static final String VALIDATE_PASSWORD  = "SecretPasswordFalse";

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

System.out.println("Generated Salt:        " + K.toHex(vault.getSalt()));
System.out.println("Hashed Password        " + K.toHex(vault.getPasswordHash()));
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(VALIDATE_PASSWORD.toCharArray()));

Output

Generated Salt:        50DC531AE50B60AA591BFA796E772F2966E74E70E0A158AD0AB476BA2CFEF861
Hashed Password        4FAF08870097A7E8C7C6AACEC403E4284810580EFC628CF04B2A3A0210EA464F85EBB8694612566972D80209224AE1B516485425F9D2DB8004CD50D6695C60CF
Used Iteration Count:  921044
Hashing Elapsed Time:  441 ms
Validate 1st Password: true
Validate 2st Password: false

Last updated 4 hours ago

🔑
Page cover image