使用由 wildfly 提供的 bouncycastle
Working with bouncycastle provided by wildfly
我正在尝试使用 Bouncy Castle 解密一些私钥 (.pfx X509Certificate)。
如果我 运行 代码独立(junit),它工作正常,但是当我 运行 它在 wildfly 上并且 arquillian 部署为 war 文件时,我面临一些问题:
org.jboss.arquillian.test.spi.ArquillianProxyException: javax.ejb.EJBException : JBAS014580: Unexpected Error
[Proxied because : Original exception caused: class java.lang.ClassFormatError: Absent Code attribute in method
that is not native or abstract in class file javax/ejb/EJBException]
我认为arquillian封装了真正的异常,但日志文件中没有再出现错误。
我在 pom 文件中声明它是提供的,以使用提供的版本。
安装的版本是:
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcmail-jdk15on-1.50.jar
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcpkix-jdk15on-1.50.jar
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcprov-jdk15on-1.50.jar
我也试过直接在pom文件中指定的版本bcprov-jdk16,作用域为compile/runtime,但还是不行
错误具体出现在这一点:
org.bouncycastle.x509.extension.X509ExtensionUtil.getIssuerAlternativeNames(java.security.cert.X509Certificate);
X509ExtensionUtil.getIssuerAlternativeNames(certificate) = >Unknown type "org.bouncycastle.x509.extension.X509ExtensionUtil"<
还有其他人遇到过这个问题或知道我该如何解决吗?有什么建议吗?
我只用了java8api就解决了我的问题,如下:
Collection<?> altNames = certificate.getSubjectAlternativeNames();
for (Object i : altNames) {
List<Object> item = (java.util.List) i;
Integer type = (Integer) item.get(0);
try {
if (type > 0) {
continue;
}
String[] arr = StringEscapeUtils.escapeHtml(new String((byte[]) item.get(1))).split(";");
return Arrays.asList(arr)
.stream()
.map(k -> k.trim())
.filter(u -> isCNPJ(u))
.findFirst().get();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
return null;
isCNPJ 只是一种过滤我需要的值的方法。
StringEscapeUtils 是 apache 通用语言 class
我正在尝试使用 Bouncy Castle 解密一些私钥 (.pfx X509Certificate)。 如果我 运行 代码独立(junit),它工作正常,但是当我 运行 它在 wildfly 上并且 arquillian 部署为 war 文件时,我面临一些问题:
org.jboss.arquillian.test.spi.ArquillianProxyException: javax.ejb.EJBException : JBAS014580: Unexpected Error
[Proxied because : Original exception caused: class java.lang.ClassFormatError: Absent Code attribute in method
that is not native or abstract in class file javax/ejb/EJBException]
我认为arquillian封装了真正的异常,但日志文件中没有再出现错误。
我在 pom 文件中声明它是提供的,以使用提供的版本。
安装的版本是:
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcmail-jdk15on-1.50.jar
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcpkix-jdk15on-1.50.jar
$WILDFLY_HOME\modules\system\layers\base\org\bouncycastle\main\bcprov-jdk15on-1.50.jar
我也试过直接在pom文件中指定的版本bcprov-jdk16,作用域为compile/runtime,但还是不行
错误具体出现在这一点:
org.bouncycastle.x509.extension.X509ExtensionUtil.getIssuerAlternativeNames(java.security.cert.X509Certificate);
X509ExtensionUtil.getIssuerAlternativeNames(certificate) = >Unknown type "org.bouncycastle.x509.extension.X509ExtensionUtil"<
还有其他人遇到过这个问题或知道我该如何解决吗?有什么建议吗?
我只用了java8api就解决了我的问题,如下:
Collection<?> altNames = certificate.getSubjectAlternativeNames();
for (Object i : altNames) {
List<Object> item = (java.util.List) i;
Integer type = (Integer) item.get(0);
try {
if (type > 0) {
continue;
}
String[] arr = StringEscapeUtils.escapeHtml(new String((byte[]) item.get(1))).split(";");
return Arrays.asList(arr)
.stream()
.map(k -> k.trim())
.filter(u -> isCNPJ(u))
.findFirst().get();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
return null;
isCNPJ 只是一种过滤我需要的值的方法。 StringEscapeUtils 是 apache 通用语言 class