Salt & Nonce
Salt
Purpose
Usage
Example
Password: "mypassword"
Salt: "randomsalt"
Hashed Password: hash("mypasswordrandomsalt")
// Java Code
// -------------------------
// Generate a Random Salt
byte[] salt = new byte[16];
SecureRandom random = new SecureRandom();
random.nextBytes(salt);
// Hash the Password with the Salt
String password = "mypassword";
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(salt);
byte[] hashedPassword = md.digest(password.getBytes(StandardCharsets.UTF_8));
// -------------------------
// Store the Salt and Hashed Password
Salt: "randomsalt"
Hashed Password: "hashed_password_value"Characteristics
Nonce
Purpose
Usage
Example
Characteristics
Best Practices
Last updated