1. 程式人生 > >java.io.IOException: DerInputStream.getLength(): lengthTag=111, too big.

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

對接支付渠道,通過絕對路徑讀取私鑰正常,在maven專案的resource目錄下,通過classpath路徑的方式讀取錯誤?

- 通過兩種方法驗證得出的輸出結果都是true

--很大可能是因為私鑰和公鑰對接不上。 

--A私鑰 A1 公鑰  B第三方私鑰 ,B1第三方公鑰

 A1給第三方,B1從第三方拿到

A加密後,第三方拿到A1解密

B加密後返回資料,我方接受用B1解密  交叉校驗

priKeyStream = new FileInputStream("/Users/xxx/workspace_pay/pay-tunnel/pay-tunnel-service/src/main/resources/cert/baofoo/
[email protected]
@200001173.pfx"); byte[] reads1 = new byte[priKeyStream.available()]; priKeyStream.read(reads1); String a = new String(reads1); System.out.println("a=" + a + " len:" + reads1.length); priKeyStream  = BaofooBizUtil.getSignCertByPath("cert/baofoo/[email protected]@200001173.pfx"); byte[] reads = new byte[priKeyStream.available()]; priKeyStream.read(reads); String b = new String(reads); System.out.println("b=" + a + " len:" + reads.length); System.out.println("a eq b : " + a.equals(b) + " len:"+ (reads.length() == .length()));

-控制檯沒有答應錯誤,翻看程式碼原來在三方工具類中包異常資訊都吞掉了,列印異常看到

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

百度了找到了解決方案,maven對它支援的幾種型別外在編譯的時候會對其他檔案改寫裡面的內容


在pom檔案中<plugins></plugins>中加入以下配置就OK

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration><encoding>UTF-8</encoding>
        <!-- 過濾字尾為pem、pfx的證書檔案 -->
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>cer</nonFilteredFileExtension>
            <nonFilteredFileExtension>pem</nonFilteredFileExtension>
            <nonFilteredFileExtension>pfx</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>

感謝作者的分享,講的很詳細:

https://blog.csdn.net/wolf_love666/article/details/51448596