Empty securerandom.strongAlgorithms Security Property



当我在 Jenkins 中设置为应用程序时。该代码在本地和其他构建环境中运行良好。在 Jenkins 中,我在构建和单元测试期间收到此错误。我们的应用程序只需要外部更改是从oracle下载JCE(Jave Crypto Extension(并替换JAVA_HOME/jre/lib/security文件夹中的策略jar。 我做到了。我可以看到日志它正在捡起那些罐子。 我仍然看到下面的错误。我需要为安全随机做任何事情吗?SecureRandom.getInstanceStrong();导致问题。有什么帮助吗?

[ERROR] Null/empty securerandom.strongAlgorithms Security Property
[ERROR]     at com.test.cipher.AesGcmCipher.generate(AesGcmCipher.java:72)
[ERROR]     at com.test.scheme.Version1CryptoSchemeAesGcmTest$1.getDefaultCipher(Version1CryptoSchemeAesGcmTest.java:27)
[ERROR]     at com.test.scheme.Version1CryptoSchemeAesGcmTest$1.getDefaultCipher(Version1CryptoSchemeAesGcmTest.java:24)
[ERROR]     at com.test.CachingCryptoCipherProvider.<init>(CachingCryptoCipherProvider.java:43)
[ERROR]     at com.test.CryptoCipherProvider.asCachingProvider(CryptoCipherProvider.java:28)
[ERROR]     at com.test.scheme.Version1CryptoSchemeAesGcmTest.createAesGcmProvider(Version1CryptoSchemeAesGcmTest.java:35)
[ERROR]     at com.test.scheme.Version1CryptoSchemeAesGcmTest.<init>(Version1CryptoSchemeAesGcmTest.java:20)
[ERROR]     ... 28 more
[ERROR] Caused by: java.security.NoSuchAlgorithmException: Null/empty securerandom.strongAlgorithms Security Property
[ERROR]     at java.security.SecureRandom.getInstanceStrong(SecureRandom.java:627)
[ERROR]     at com.test.cipher.AesGcmCipher.generate(AesGcmCipher.java:62)
[ERROR]     ... 34 more`

下面是我的 java 代码。

public class AesGcmCipher {
public static AesGcmCipher generate(BiConsumer<AesGcmCipher, SecretKey> consumer) {
try {
UUID cipherId = UUID.randomUUID();
SecureRandom random = SecureRandom.getInstanceStrong();
KeyGenerator keyGen = KeyGenerator.getInstance(AES);
AesGcmCipher cipher = new AesGcmCipher(cipherId, secretKey, new Date());
return cipher;
} catch (NoSuchAlgorithmException ex) {
LOGGER.error(msg);
throw new CryptoException(msg, ex);
}
}
}

仅供参考,詹金斯正在运行java version "1.8.0_73"。 在其他具有版本1.8.0_511.8.0_91的机器上完美运行的代码

这应该是你的 jdk 的问题。您能否验证此文件$JAVA_HOME/jre/lib/security/java.security

securerandom.source=file:/dev/random
securerandom.strongAlgorithms=NativePRNGBlocking:SUN

这是我的配置,可能需要重新安装JDK

最新更新