add method

This commit is contained in:
Looly
2020-11-17 23:41:14 +08:00
parent 9ca25e26d6
commit 11e6a28113
8 changed files with 89 additions and 17 deletions

View File

@@ -71,7 +71,7 @@ public class RandomUtil {
}
/**
* 获取{@link SecureRandom},类提供加密的强随机数生成器 (RNG)<br>
* 获取SHA1PRNG的{@link SecureRandom},类提供加密的强随机数生成器 (RNG)<br>
* 注意此方法获取的是伪随机序列发生器PRNGpseudo-random number generator
*
* <p>
@@ -81,11 +81,31 @@ public class RandomUtil {
* @since 3.1.2
*/
public static SecureRandom getSecureRandom() {
return getSecureRandom(null);
}
/**
* 获取SHA1PRNG的{@link SecureRandom},类提供加密的强随机数生成器 (RNG)<br>
* 注意此方法获取的是伪随机序列发生器PRNGpseudo-random number generator
*
* <p>
* 相关说明见https://stackoverflow.com/questions/137212/how-to-solve-slow-java-securerandom
*
* @param seed 随机数种子
* @return {@link SecureRandom}
* @since 5.5.2
*/
public static SecureRandom getSecureRandom(byte[] seed) {
SecureRandom random;
try {
return SecureRandom.getInstance("SHA1PRNG");
random = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new UtilException(e);
}
if(null != seed){
random.setSeed(seed);
}
return random;
}
/**