转载于:/blog/1853150
用openssl 生成的密钥老是报以下错误:
Java代码java.security.spec.InvalidKeySpecException:java.security.InvalidKeyException:IOException:DERinput,Integertagerror atsun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:200) atjava.security.KeyFactory.generatePrivate(KeyFactory.java:342) ponent.payment.payplatform.alipay.util.RSASignature.getPrivateKey(RSASignature.java:84) ponent.payment.payplatform.alipay.util.RSASignature.main(RSASignature.java:161) Causedby:java.security.InvalidKeyException:IOException:DERinput,Integertagerror atsun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:344) atsun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:350) atsun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:74) atsun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:58) atsun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:299) atsun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:196) ...3more
后来发现,原来是支付宝,生成的命令有问题,参数放错位置,害死人。
将(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