1.检查私钥文件和私钥密码是否是一对,如果不是一对不能加密出数据。

在windows下可以采用双击私钥文件输入私钥密码导入,如果能导入则为一致,如提示【输入的密码不正确】则不能加密成功,例如:

在liunx下则可以在openssl 执行命令:openssl pkcs12 -nodes -nokeys -in 8000013189_pri.pfx -passin pass:123456 -out test.cer
错误的情况:Mac verify error: invalid password?

正确的情况:MAC verified OK

2.报错:DerInputStream.getLength(): lengthTag=111, too big和加密数据为空

可能在maven项目中密钥文件统一放到项目src/main/resources的某个目录下,打包部署运行中出现。原因为maven打包中没有排除密钥文件,证书就会被修改。
办法一:推荐把密钥文件存在单独的目录,不参与maven打包。
办法二:可以采用过滤证书文件的方式,但是不推荐。

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-resources-plugin</artifactId>
  4. <configuration>
  5. <encoding>UTF-8</encoding>
  6. <!-- 过滤后缀为cer、pfx的证书文件 -->
  7. <nonFilteredFileExtensions>
  8. <nonFilteredFileExtension>cer</nonFilteredFileExtension>
  9. <nonFilteredFileExtension>pfx</nonFilteredFileExtension>
  10. </nonFilteredFileExtensions>
  11. </configuration>
  12. </plugin>
文档更新时间: 2019-06-17 12:12   作者:support