提交 f79c72e1 编写于 作者: 有来技术

fix(KaptchaTextCreator): 随机数生成器调整为/dev/urandom非阻塞熵池

Closes #I4E0WL
上级 a2199dac
......@@ -14,7 +14,11 @@ import java.security.SecureRandom;
public class KaptchaTextCreator extends DefaultTextCreator {
private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(",");
private SecureRandom rand = SecureRandom.getInstanceStrong();
// https://gitee.com/youlaitech/youlai-mall/issues/I4E0WL?from=project-issue
// private SecureRandom random = SecureRandom.getInstanceStrong(); // /dev/random 作为熵池,熵越大随机性越好,熵池数量不足就会阻塞线程,适用随机数比较高的请求。
private SecureRandom random = new SecureRandom(); // /dev/urandom 作为熵池,非阻塞的随机数生成器,重复使用熵池中的数据以产生伪随机数据,不会产生阻塞,适用生成较低强度的伪随机数。
public KaptchaTextCreator() throws NoSuchAlgorithmException {
}
......@@ -22,10 +26,10 @@ public class KaptchaTextCreator extends DefaultTextCreator {
@Override
public String getText() {
Integer result = 0;
int x = this.rand.nextInt(10);
int y = this.rand.nextInt(10);
int x = this.random.nextInt(10);
int y = this.random.nextInt(10);
StringBuilder suChinese = new StringBuilder();
int randomoperands = (int) Math.round(rand.nextDouble() * 2);
int randomoperands = (int) Math.round(random.nextDouble() * 2);
if (randomoperands == 0) {
result = x * y;
suChinese.append(CNUMBERS[x]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册