How to generate SALT value in Java?

java, salt, spring-security

Solution

final Random r = new SecureRandom();
byte[] salt = new byte[32];
r.nextBytes(salt);
/** String encodedSalt = Base64.encodeBase64String(salt); */

Problem

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

Original source