Skip to content

Instantly share code, notes, and snippets.

@Jaymo
Created February 29, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaymo/c97b6a345efe9ad1a156 to your computer and use it in GitHub Desktop.
Save Jaymo/c97b6a345efe9ad1a156 to your computer and use it in GitHub Desktop.
public static final int SALT_LENGTH = 256;
private static final String RANDOM_ALGORITHM = "SHA1PRNG";
public String generateSalt() throws CryptoException {
try {
SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM);
byte[] salt = new byte[SALT_LENGTH];
random.nextBytes(salt);
String saltHex = Util.HexEncoder.toHex(salt);
return saltHex;
} catch (Exception e) {
throw new CryptoException("Unable to generate salt", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment