为分离的 XAdES 签名添加对解析程序的引用



我必须为项目创建自己的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");

而不是我正在使用的解析器。

相关内容

  • 没有找到相关文章

最新更新