转载于:http://nassir.iteye.com/blog/1853150
用openssl 生成的密钥老是报以下错误:
- java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : DER input, Integer tag error
- at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:200)
- at java.security.KeyFactory.generatePrivate(KeyFactory.java:342)
- at com.qhx.component.payment.payplatform.alipay.util.RSASignature.getPrivateKey(RSASignature.java:84)
- at com.qhx.component.payment.payplatform.alipay.util.RSASignature.main(RSASignature.java:161)
- Caused by: java.security.InvalidKeyException: IOException : DER input, Integer tag error
- at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:344)
- at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:350)
- at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:74)
- at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:58)
- at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:299)
- at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:196)
- ... 3 more
后来发现,原来是支付宝,生成的命令有问题,参数放错位置,害死人。
将(3) 的命令改为:
openssl pkcs8 -topk8 -nocrypt -inform PEM -in rsa_private_key.pem -outform PEM outform
完整命令:
1.
openssl genrsa -out rsa_private_key.pem 1024
2.
openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
3.openssl pkcs8 -topk8 -nocrypt -inform PEM -in rsa_private_key.pem -outform PEM outform
来源:CSDN
作者:wengjiasi_awhg_2015
链接:https://blog.csdn.net/wengjiasi_AWHG_2015/article/details/45534061