java - 移动到资源文件夹时生成的证书停止工作

标签 java ssl certificate apple-push-notifications

我在使用生成的证书连接到 Apple 推送服务时遇到问题。 当生成的 p12 文件位于我的 src/main/java 文件夹中时一切正常,但我将其移至 src/main/resources 并且它决定停止工作并出现以下错误:

DerInputStream.getLength(): lengthTag=111, too big.

要了解更多细节: 我正在使用 notnoop 推送通知库并按照 Ray Wenderlich 的教程生成证书。之后,我习惯于按照以下命令生成用于 java 的 p12 文件:

openssl x509 -in aps_development.cer -inform DER -out aps_development.pem -outform PEM
openssl pkcs12 -nocerts -in single.p12 -out single.pem
openssl pkcs12 -export -inkey single.pem -in aps_development.pem -out dual.p12

之后,我将 dual.p12 移到了我的 java 项目中。起初文件在我的/src/main/java 文件夹中,假设在 com.company.push.certificates (而请求文件的代码在 com.company.push)。我使用

请求输入流
InputStream stream = this.getClass().getResourceAsStream("certificates/dual.p12");

这在开发中工作正常,但在构建项目(使用 maven)时却不行,这就是为什么我使用完全相同的包将资源移动到资源文件夹。 仍然可以找到资源,但现在我得到了上面提到的 java.io.IOException

有人知道是什么原因造成的吗?

Ps: 当我将文件移回 src/main/java 中的包时,一切又都正常了,所以证书似乎是有效的。

最佳答案

发生这种情况是因为 maven 的资源过滤正在破坏您的 p12 文件。

我们通过在 pom.xml 中从 Maven 资源过滤中排除 p12 文件来解决这个问题:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
            <exclude>**/*.p12</exclude>
        </excludes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*.p12</include>
        </includes>
    </resource>
</resources>

关于java - 移动到资源文件夹时生成的证书停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17298126/

相关文章:

java - 如何在android中检查时间只在晚上的两个时间之间

http - 加密电子邮件 VS SSL 数据传输 : which is better?

java - 如何将项目ID传递给另一个 Activity ?

java - 如何为抽屉导航项目添加长按功能?

java - 使用lambda在Java流中调用带有参数的构造函数

php - 基于 Javascript 的 SSL

php - cURL错误60 : SSL certificate in Laravel 5 while Facebook authentication如何解决

powershell - 需要自签名证书 Win2012 r2 SHA256 4 年到期

wcf - 无法验证消息中的至少一个安全 token

ios - 从 iOS 应用程序中的证书文件获取公钥信息