From 3f92477c26978e0c2a404a0f33c3ce8d022a41d4 Mon Sep 17 00:00:00 2001 From: Jesse-Ma <24167796@qq.com> Date: Mon, 26 Dec 2022 11:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- .../com/flagnote/gateway/utils/RandomUtils.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b96469f..7510d2e 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# flagnote-gateway \ No newline at end of file +# flagnote-gateway + +-Djava.security.egd=file:/dev/./urandom \ No newline at end of file diff --git a/src/main/java/com/flagnote/gateway/utils/RandomUtils.java b/src/main/java/com/flagnote/gateway/utils/RandomUtils.java index 2c9a6aa..86752fe 100644 --- a/src/main/java/com/flagnote/gateway/utils/RandomUtils.java +++ b/src/main/java/com/flagnote/gateway/utils/RandomUtils.java @@ -1,15 +1,21 @@ package com.flagnote.gateway.utils; -import java.util.concurrent.ThreadLocalRandom; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; public class RandomUtils { + public static SecureRandom sr = null; - public static ThreadLocalRandom getRandom() { - return ThreadLocalRandom.current(); + static { + try { + sr = SecureRandom.getInstanceStrong(); + } catch (NoSuchAlgorithmException e) { + sr = new SecureRandom(); + } } public static Integer nextInt(Integer num) { - return getRandom().nextInt(num); + return sr.nextInt(num); } } \ No newline at end of file