7

当我调用 java.security.KeyStore 下的函数时:

public final Key getKey(String alias, char[] password)

我收到以下错误:

java.security.UnrecoverableKeyException: Rejected by the jceks.key.serialFilter or jdk.serialFilter property
  at com.sun.crypto.provider.KeyProtector.unseal(KeyProtector.java:352)
  at com.sun.crypto.provider.JceKeyStore.engineGetKey(JceKeyStore.java:136)
  at java.security.KeyStore.getKey(KeyStore.java:1023)

此错误在任何 Java 文档中都不存在,只是间歇性发生。此错误的原因是什么以及如何解决?

更新:现在@zeal 透露它与http://www.oracle.com/technetwork/java/javase/8u171-relnotes-4308888.html#JDK-8189997有关。因此,无需额外配置,就可以使用 Key 实现的几个选项。但是在发行说明中我发现了一个声明:

存储不序列化为上述类型的 SecretKey 的客户必须修改过滤器以使密钥可提取。

这似乎是新事物,因为它表明密钥的序列化可以被程序覆盖,这是使其他密钥类型与 JCEKS 密钥库兼容的唯一方法吗?

4

2 回答 2

2

您可以打开 /jre/lib/security/java.security 文件并尝试找到属性jceks.key.serialFilter并在那里添加您的过滤器类/包。

在我结束时 jceks.key.serialFilter 属性的旧条目是:

jceks.key.serialFilter = java.lang.Enum;java.security.KeyRep;java.security.KeyRep$Type;javax.crypto.spec.SecretKeySpec;!*

添加了 org.apache.hadoop.crypto.key.**,因此 jceks.key.serialFilter 属性的新条目是:

jceks.key.serialFilter = java.lang.Enum;java.security.KeyRep;java.security.KeyRep$Type;javax.crypto.spec.SecretKeySpec;org.apache.hadoop.crypto.key.**;!*
于 2018-07-09T07:48:03.800 回答
2

its causing because of issue in latest java version JDK-8 build 171. there has been a switch from jks to pkcs12 and it's the open issue at java side (latest JDK-8 build 171) in jcrypto: https://github.com/jcryptool/core/issues/120.

workaround for this is to switch JRE 8 build 171 build to JRE 8 build 144/121

于 2018-07-06T06:58:26.447 回答