How to generate SALT value in Java?

本小妞迷上赌 提交于 2019-12-20 08:48:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!