PKCS12 not found 的一种解决方案

在对报文进行证书签名时,报错信息如下 

com.ly.asgw.job.allinpay.util.AIPGException: 加签失败 keyfile=E:/certs/Allinpay/20058400002509504.p12 pass=111111 CAUSE: PKCS12 not found
	at com.ly.asgw.job.allinpay.util.AIPGSignature.signMsg(AIPGSignature.java:88)
	at com.ly.asgw.job.allinpay.util.DemoUtil.buildSignedXml(DemoUtil.java:75)
	at com.ly.asgw.job.allinpay.demo.Tranx100014.main(Tranx100014.java:45)
Caused by: java.security.KeyStoreException: PKCS12 not found
	at java.security.KeyStore.getInstance(KeyStore.java:940)
	at com.ly.asgw.job.allinpay.util.AIPGSignature.signMsg(AIPGSignature.java:58)
	... 2 more
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: PKCS12, provider: BC, class: org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore)
	at java.security.Provider$Service.newInstance(Provider.java:1684)
	at sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
	at sun.security.jca.GetInstance.getInstance(GetInstance.java:218)
	at java.security.Security.getImpl(Security.java:726)
	at java.security.KeyStore.getInstance(KeyStore.java:937)
	... 3 more
Caused by: java.lang.IllegalArgumentException: can't create cert factory - java.security.NoSuchProviderException: no such provider: BC
	at org.bouncycastle.jce.provider.JDKPKCS12KeyStore.<init>(Unknown Source)
	at org.bouncycastle.jce.provider.JDKPKCS12KeyStore$BCPKCS12KeyStore.<init>(Unknown Source)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.security.Provider$Service.newInstance(Provider.java:1662)
	... 7 more

解决方案如下:添加一行 在初始化 KeyStore 之前

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

来源  https://my.oschina.net/u/3690153/blog/4791205

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值