gpt4 book ai didi

java - 添加对解析器的引用以获取分离的 XAdES 签名

转载 作者:行者123 更新时间:2023-11-30 07:36:54 25 4
gpt4 key购买 nike

我必须为一个项目创建我自己的 XAdES 签名,除了分离的签名之外,一切都工作正常。据我了解,我必须添加对 XML 对象的引用,该对象将指向存储原始文档的容器。我已经尝试使用 ResolverAnonymous 和 ResolverLocalFileSystem。

XMLSignature sig = new XMLSignature(docToBeSigned, "", sigAlgorithm);
Element element = sig.getElement();

//adding signedinfo, keyinfo and xades properties in between

ResolverLocalFilesystem resolver = new ResolverLocalFilesystem();
//ResolverAnonymous resolver = new ResolverAnonymous(documentToSign);
sig.addResourceResolver(resolver);

sig.addDocument("DetachedObjectReference-1", null,
ESIGUtils.algorithmIDtoURN(hashAlgorithmID), /* it sends the corresponding SHA-1 URL */
SignedDataObject-Reference", null);

Element objeto = docToBeSigned.createElement("ds:Object");
objeto.setAttribute("Id", "Object-1");

element.appendChild(objeto);

sig.sign(privateKey);

return docToBeSigned;

我收到的错误如下:

Original Exception was org.apache.xml.security.signature.ReferenceNotInitializedException: Could not find a resolver for URI DetachedObjectReference-1 and Base 
Original Exception was org.apache.xml.security.signature.ReferenceNotInitializedException: Could not find a resolver for URI DetachedObjectReference-1 and Base
Original Exception was org.apache.xml.security.utils.resolver.ResourceResolverException: Could not find a resolver for URI DetachedObjectReference-1 and Base

有人能告诉我我的错误在哪里吗?

提前致谢!

最佳答案

好的,已修复。

Apache XML Security 有一个 ID 解析器,它添加了我缺少的引用。需要添加下一个代码片段才能使签名正常工作:

Element objeto = docToBeSigned.createElementNS(
Constants.SignatureSpecNS, "ds:Object");
objeto.setAttributeNS(null, Constants._ATT_ID, "DetachedSignatureReference");
IdResolver.registerElementById(objeto, "DetachedSignatureReference");

而不是我使用的解析器。

关于java - 添加对解析器的引用以获取分离的 XAdES 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35268889/

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