1. 程式人生 > >Jar包中讀取微信支付證書

Jar包中讀取微信支付證書

instance onf har 解決辦法 key 通過 des arr encoding

通過this.getClass().getResourceAsStream()讀入數據

KeyStore keyStore = KeyStore.getInstance("PKCS12");

keyStore.load(instream, mchId.toCharArray());

報錯:

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

原因:打包時證書文件被篡改

解決辦法:

1.spring-boot

<build>
<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>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

2.apache
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<!-- 過濾後綴為p12的證書文件 -->
<nonFilteredFileExtensions>
<nonFilteredFileExtension>p12</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>


Jar包中讀取微信支付證書