【问题标题】:Working with bouncycastle provided by wildfly使用 wildfly 提供的 bouncycastle
【发布时间】:2015-05-22 18:52:08
【问题描述】:

我正在尝试使用 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"<

其他人曾经遇到过这个问题或知道我该如何解决?有什么建议吗?

【问题讨论】:

    标签: java x509certificate bouncycastle wildfly-8 pfx


    【解决方案1】:

    我只使用 java 8 api 解决了我的问题,如下所示:

    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 commons lang 类

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      • 2015-10-03
      • 1970-01-01
      相关资源
      最近更新 更多