我们在 Linux、Solaris 和 AIX 平台上使用 tomcat、weblogic、websphere、apache(主要是 java)。对于加密,我们使用 SSL。要生成私钥/公钥对,我们使用 keytool。有关 java keytool 的文章建议我们避免使用/dev/urandom 作为熵设备。鉴于/dev/urandom 是默认值,我们如何在不使用/dev/urandom 的情况下创建私钥/公钥对?
最佳答案
感兴趣的文件位于您的 JRE lib/security
文件夹中,名为 java.security
。在其中您会发现以下行:
securerandom.source=file:/dev/urandom
并且文件中有描述其行为的注释。如果需要,您可以将其切换为使用 /dev/random
(这更安全,但由于熵问题可能需要很长时间):
#
# Select the source of seed data for SecureRandom. By default an
# attempt is made to use the entropy gathering device specified by
# the securerandom.source property. If an exception occurs when
# accessing the URL then the traditional system/thread activity
# algorithm is used.
#
# On Solaris and Linux systems, if file:/dev/urandom is specified and it
# exists, a special SecureRandom implementation is activated by default.
# This "NativePRNG" reads random bytes directly from /dev/urandom.
#
# On Windows systems, the URLs file:/dev/random and file:/dev/urandom
# enables use of the Microsoft CryptoAPI seed functionality.
#
securerandom.source=file:/dev/urandom
#
# The entropy gathering device is described as a URL and can also
# be specified with the system property "java.security.egd". For example,
# -Djava.security.egd=file:/dev/urandom
# Specifying this system property will override the securerandom.source
# setting.
你可以看到更多关于Java policy files here in the Oracle docs的信息
这是关于 overriding default Java security 的简短教程还有
关于ssl - 使用keytool时如何避免/dev/urandom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24175157/