问题
What's the best way to produce a SALT value in Java as a String that's at least 32 bytes long?
回答1:
final Random r = new SecureRandom();
byte[] salt = new byte[32];
r.nextBytes(salt);
/** String encodedSalt = Base64.encodeBase64String(salt); */
回答2:
In SpringSecurity you can use org.springframework.security.crypto.keygen.KeyGenerators
http://static.springsource.org/spring-security/site/docs/3.1.x/apidocs/org/springframework/security/crypto/keygen/KeyGenerators.html
http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#spring-security-crypto-keygenerators
来源:https://stackoverflow.com/questions/18268502/how-to-generate-salt-value-in-java