问题
I want to load a KeyStore with the load method but when I use it I got an error. I don't understant what ECParameter is.
try {
FileInputStream is =new FileInputStream(new File("D:\\UZ\\key_privateUZ.p12"));
ks = KeyStore.getInstance("PKCS12");
password="1234".toCharArray();
ks.load(is, password);
} catch (Exception e) {
e.printStackTrace();
}
my error:
java.security.cert.CertificateParsingException: java.io.IOException: Only named ECParameters supported
at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:171)
at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1788)
at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:202)
at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:97)
at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
at sun.security.pkcs12.PKCS12KeyStore.loadSafeContents(PKCS12KeyStore.java:1441)
at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1313)
at java.security.KeyStore.load(KeyStore.java:1214)
at Main.main(Main.java:21) Caused by: java.io.IOException: Only named ECParameters supported
at sun.security.ec.ECParameters.decodeParameters(ECParameters.java:202)
at sun.security.ec.ECParameters.engineInit(ECParameters.java:319)
at java.security.AlgorithmParameters.init(AlgorithmParameters.java:293)
at sun.security.x509.AlgorithmId.decodeParams(AlgorithmId.java:139)
at sun.security.x509.AlgorithmId.<init>(AlgorithmId.java:114)
at sun.security.x509.AlgorithmId.parse(AlgorithmId.java:381)
at sun.security.x509.X509Key.parse(X509Key.java:168)
at sun.security.x509.CertificateX509Key.<init>(CertificateX509Key.java:75)
at sun.security.x509.X509CertInfo.parse(X509CertInfo.java:705)
at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:169)
... 8 more
Regars
Wazol
回答1:
You'll find plenty of information on EC (elliptic curve) parameters if you do a search. In particular, the JDK Code which throws that exception.
If you look in the relevant method, you will see a commented out section after the exception which indicates:
It is left as a starting point for a complete parsing implementation
In other words the JDK doesn't support all possible encodings.
You might have better luck using Bouncy Castle which generally has more features than the basic JDK.
It might also help if you explain how the data in the keystore was generated.
来源:https://stackoverflow.com/questions/15545258/error-loading-keystorepkcs12