🔨
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 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

Last updated 1 hour ago

🔑
Page cover image