1

我必须为一个项目创建我自己的 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

谁能说我的错误在哪里?

提前致谢!

4

1 回答 1

1

好吧,修好了。

Apache XML Security 有一个 ID 解析器,它添加了我缺少的参考。需要添加下一个代码片段才能使签名生效:

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

而不是我使用的解析器。

于 2016-02-08T14:30:20.570 回答