收藏
回答

java.io.IOException: Short read of DER length什么问题?

使用申请入驻接口提交你的小微商户资料,使用公钥(public.pem)加密数据报错。。。。。。

javax.security.cert.CertificateException: InvocationTargetException: javax.security.cert.CertificateException: Unable to initialize, java.io.IOException: Short read of DER length


    at java.base/javax.security.cert.X509Certificate.getInst(X509Certificate.java:243)

    at java.base/javax.security.cert.X509Certificate.getInstance(X509Certificate.java:202)

    at com.xiaoweishanghu.demo.xiaowei.WxXiaoWeiUtils.rsaEncrypt(WxXiaoWeiUtils.java:110)

    at com.xiaoweishanghu.demo.DemoApplicationTests.applyment(DemoApplicationTests.java:122)

    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.base/java.lang.reflect.Method.invoke(Method.java:566)

    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

    at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)

    at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)

    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)

    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)

    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)

    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)

    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)

    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)

    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)

    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)

    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)

    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

1、参考解决方案:

需要替换jre\lib\security目录下的两个jar包,US_export_policy.jar和local_policy.jar,从Oracle官方网站查找jce_policy-8.zip直接点击文中附件(包含了JDK1.6,JDK1.7,JDK1.8),替换本地的jre\lib\security目录下这两个JAR包

2、检查证书是否正确


这两个方案都已经试过了,还是报同样的错误,脑壳疼了,各位同学给点思路

回答关注问题邀请回答
收藏

1 个回答

  • 逗比
    逗比
    2021-07-29

    试下 读取证书流的时候每次都新读取? 而不是 读取一次放在静态变量中

    2021-07-29
    有用
    回复
登录 后发表内容
问题标签