狗日的支付宝
用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
我按照你的方法从新生成了密钥可是还是报者个错误...
在Mac上测试与参数的顺序无关, 加入下面的代码可以解决
其实这个问题还与系统有关,有些xp可以有些不可以,不过出现这问题,按我这个方式可以成功
狗日的支付宝,我就这个问题卡了几个小时
狗日的支付宝太坑爹了!