1

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

4

2 回答 2

1

如果您进行搜索,您会发现大量有关 EC(椭圆曲线)参数的信息。特别是引发该异常的 JDK 代码

如果您查看相关方法,您将在异常后看到一个注释掉的部分,表示:

它作为一个完整的解析实现的起点

换句话说,JDK 不支持所有可能的编码。

使用通常比基本 JDK 具有更多功能的Bouncy Castle可能会更好。

如果您解释密钥库中的数据是如何生成的,它也可能会有所帮助。

于 2013-03-21T10:58:49.123 回答
0

我解决了这个问题在 ECKey class ECParameterSpec papamSpec = ECNamedCurveTable.getParameterSpec(SECP);

于 2020-04-16T01:16:28.760 回答