JavaWeb问题记录——Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [280] milliseconds.

摘要:本文主要记录了在启动Tomcat时,出现的一个警告以及解决办法。

问题重现

启动Tomcat时,后台打印警告:

1 27-Nov-2019 17:26:48.057 警告 [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [280] milliseconds.

Java的版本是1.8,Tomcat的版本是9.0.29,运行环境是Windows 10。

解决办法

在Java的安装目录下,找到 jre\lib\security 目录,打开 java.security 文件,找到如下配置:

1 securerandom.source=file:/dev/random

改为:

1 securerandom.source=file:/dev/./random

保存,然后重启Tomcat服务器即可。

问题说明

Tomcat 7/8都使用org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom类产生安全随机类SecureRandom的实例作为会话ID。

SHA1PRNG是基于SHA-1算法的伪随机数生成器,用来生成保密性较强的伪随机数。

在SHA1PRNG中,有一个种子产生器,它根据配置执行各种操作。

1)如果 java.security.egd 属性或 securerandom.source 属性指定的是 file:/dev/random 或 file:/dev/urandom ,那么JVM会使用本地种子产生器NativeSeedGenerator,它会调用super()方法,即调用SeedGenerator.URLSeedGenerator(/dev/random)方法进行初始化。

2)如果 java.security.egd 属性或 securerandom.source 属性指定的是其它已存在的URL,那么会调用SeedGenerator.URLSeedGenerator(url)方法进行初始化。

未完待续

01-02 21:41