0

当我在 Jenkins 中设置为应用程序时。该代码在本地和其他构建环境中运行良好。在 Jenkins 中,我在构建和单元测试期间遇到了这个错误。我们的应用程序只需要外部更改是从 oracle 下载 JCE(Java 加密扩展)并替换 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_51在具有版本和的其他机器上完美运行的代码1.8.0_91

4

1 回答 1

1

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

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

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

于 2018-10-18T21:44:04.907 回答