How to generate SALT value in Java?

Tom Bell picture Tom Bell · Aug 16, 2013 · Viewed 24.2k times · Source

What's the best way to produce a SALT value in Java as a String that's at least 32 bytes long?

Answer

Shamim Ahmmed picture Shamim Ahmmed · Aug 16, 2013
final Random r = new SecureRandom();
byte[] salt = new byte[32];
r.nextBytes(salt);
/** String encodedSalt = Base64.encodeBase64String(salt); */