Java - 使用 ECDSA(椭圆曲线)创建 XML 数字签名
Java - Create XML Digital Signature using ECDSA (Elliptic Curve)
我们可以使用 RSA 密钥创建 XML 数字签名。但是如何使用椭圆曲线密钥来签署 xml 文件?我收到诸如 -
之类的错误消息
Exception in thread "main" java.security.KeyException: ECKeyValue not supported
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.<init>(DOMKeyValue.java:350)
at org.jcp.xml.dsig.internal.dom.DOMKeyInfoFactory.newKeyValue(DOMKeyInfoFactory.java:71)
at csr.ExtractEC.main(XMLSignatureECTest.java:57)
Caused by: java.lang.ClassNotFoundException: sun/security/ec/ECParameters
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.getMethods(DOMKeyValue.java:367)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.run(DOMKeyValue.java:343)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.run(DOMKeyValue.java:339)
at java.security.AccessController.doPrivileged(Native Method)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.<init>(DOMKeyValue.java:338)
... 2 more
我使用下面的代码创建了 SignatureMethod 和 KeyInfo -
String url = "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256";
SignatureMethod signatureMethod = factory.newSignatureMethod(url, null);
SignedInfo signedInfo = factory.newSignedInfo(c14n, signatureMethod, Collections.singletonList(reference));
PrivateKey privateKey = Utils.generatePrivateEC("e:\certs\ec\ec.key.p8");
Certificate certificate = Utils.generatePublic("e:\certs\ec\ec.cer");
KeyInfoFactory keyInfoFactory = factory.getKeyInfoFactory();
KeyValue keyValue = keyInfoFactory.newKeyValue(certificate.getPublicKey());
KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyValue));
JDK - 甲骨文 JDK 8
安全提供商 - BouncyCastle 和 Sun。
好像在this junit test中有人给你做了个例子。
我们可以使用 RSA 密钥创建 XML 数字签名。但是如何使用椭圆曲线密钥来签署 xml 文件?我收到诸如 -
之类的错误消息Exception in thread "main" java.security.KeyException: ECKeyValue not supported
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.<init>(DOMKeyValue.java:350)
at org.jcp.xml.dsig.internal.dom.DOMKeyInfoFactory.newKeyValue(DOMKeyInfoFactory.java:71)
at csr.ExtractEC.main(XMLSignatureECTest.java:57)
Caused by: java.lang.ClassNotFoundException: sun/security/ec/ECParameters
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.getMethods(DOMKeyValue.java:367)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.run(DOMKeyValue.java:343)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.run(DOMKeyValue.java:339)
at java.security.AccessController.doPrivileged(Native Method)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC.<init>(DOMKeyValue.java:338)
... 2 more
我使用下面的代码创建了 SignatureMethod 和 KeyInfo -
String url = "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256";
SignatureMethod signatureMethod = factory.newSignatureMethod(url, null);
SignedInfo signedInfo = factory.newSignedInfo(c14n, signatureMethod, Collections.singletonList(reference));
PrivateKey privateKey = Utils.generatePrivateEC("e:\certs\ec\ec.key.p8");
Certificate certificate = Utils.generatePublic("e:\certs\ec\ec.cer");
KeyInfoFactory keyInfoFactory = factory.getKeyInfoFactory();
KeyValue keyValue = keyInfoFactory.newKeyValue(certificate.getPublicKey());
KeyInfo keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyValue));
JDK - 甲骨文 JDK 8 安全提供商 - BouncyCastle 和 Sun。
好像在this junit test中有人给你做了个例子。