如何在Java中生成SALT值?

如何在Java中生成SALT值?,java,spring-security,salt,Java,Spring Security,Salt,在Java中,将SALT值生成为至少32字节长的字符串的最佳方法是什么?在SpringSecurity中,您可以使用org.springframework.security.crypto.keygen.KeyGenerators final Random r = new SecureRandom(); byte[] salt = new byte[32]; r.nextBytes(salt); /** String encodedSalt = Base64.encodeBase64String(

在Java中,将SALT值生成为至少32字节长的字符串的最佳方法是什么?

在SpringSecurity中,您可以使用
org.springframework.security.crypto.keygen.KeyGenerators

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


盐值只是随机产生的值。您想要什么字符范围?注意:字符使用2字节。你的意思是你想要一个
字节[32]
作为salt吗?我想要像沙米姆建议的那样将32个随机字节编码为字符串。