gpt4 book ai didi

Java - 使用 ECDSA(椭圆曲线)创建 XML 数字签名

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:35:22 26 4
gpt4 key购买 nike

我们可以使用 RSA key 创建 XML 数字签名。但是如何使用椭圆曲线 key 对 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$1.run(DOMKeyValue.java:343)
at org.jcp.xml.dsig.internal.dom.DOMKeyValue$EC$1.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 someone is make an example for you.

关于Java - 使用 ECDSA(椭圆曲线)创建 XML 数字签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51961749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com