Created
February 29, 2016 08:21
-
-
Save Jaymo/c97b6a345efe9ad1a156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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