我想用load方法加载KeyStore但是当我使用它时出现错误。我不明白ECParameter是什么。
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();
}
我的错误:
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
答案 0 :(得分:1)
如果您进行搜索,您会发现有关EC(椭圆曲线)参数的大量信息。特别是JDK Code which throws that exception。
如果您查看相关方法,您会在异常后看到一个注释掉的部分,表示:
它留作完整解析实现的起点
换句话说,JDK不支持所有可能的编码。
使用Bouncy Castle可能会有更好的运气,{{3}}通常具有比基本JDK更多的功能。
如果您解释密钥库中的数据是如何生成的,也可能会有所帮助。
答案 1 :(得分:0)
我这样解决了这个问题 在ECKey类中 ECParameterSpec papamSpec = ECNamedCurveTable.getParameterSpec(SECP);