我正在使用 xades4j 来生成 xades 签名。我想在参考中包含 xpath 转换。我的问题是它是一个分离的签名并且 xpath 具有命名空间......
我尝试使用以下 xml(摘录):
<collection xmlns:t="http://test.xades4j/tracks" Id="root">
<album>
<title>Questions, unanswered</title>
<artist>Steve and the flubberblubs</artist>
<year>1989</year>
<t:tracks xmlns:t="http://test.xades4j/tracks">
<t:song length="4:05" tracknumber="1">
<t:title>What do you know?</t:title>
<t:artist>Steve and the flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:31</t:lastplayed>
</t:song>
<t:song length="3:45" tracknumber="2">
<t:title>Who do you know?</t:title>
<t:artist>Steve and the flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:35</t:lastplayed>
</t:song>
如果我尝试使用以下代码对该文档进行信封签名:
String xpathString = "/collection/album/t:tracks/t:song[ @tracknumber = 1 ]";
DataObjectDesc obj1 = new DataObjectReference("");
obj1.withTransform(new EnvelopedSignatureTransform());
obj1.withTransform(XPath2Filter.intersect( xpathString ));
SignedDataObjects objs = new SignedDataObjects( obj1 );
Document doc = getDocument(path+fileName);
signer.sign( objs, doc.getDocumentElement() );
它工作正常,参考如下所示:
<ds:Reference Id="xmldsig-44c42d30-9a42-4290-afba-b89dc807a668-ref0" URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<ds:Transform Algorithm="http://www.w3.org/2002/06/xmldsig-filter2">
<dsig-xpath:XPath xmlns:dsig-xpath="http://www.w3.org/2002/06/xmldsig-filter2" Filter="intersect">/collection/album/t:tracks/t:song[ @tracknumber = 1 ]</dsig-xpath:XPath>
</ds:Transform>
</ds:Transforms>
但是,如果我尝试使用分离版本,请使用以下代码:
String xpathString = "/collection/album/t:tracks/t:song[ @tracknumber = 1 ]";
DataObjectDesc obj1 = new DataObjectReference( fileName );
obj1.withTransform(XPath2Filter.intersect( xpathString ));
SignedDataObjects objs = new SignedDataObjects( obj1 );
objs.withBaseUri( "file:///"+path );
signer.sign( objs, db.newDocument());
我收到错误:前缀必须解析为命名空间:t
我的问题类似于这里描述的问题:namespace and xpath 但是没有答案,我所拥有的有点不同。我邀请这个问题的答案可能对我有帮助......
那么,如何在 xades4j 中将命名空间设置为转换?