首页 > 解决方案 > 使用 xades4j 签名 UBL2.1 发票

问题描述

我尝试使用 xades4j 库对 UBL2.1 Invoice 进行数字签名。

UBL 将 xpath 转换定义为:

count(ancestor-or-self::sig:UBLDocumentSignatures | here()/ancestor::sig:UBLDocumentSignatures[1]) > count(ancestor-or-self::sig:UBLDocumentSignatures)

并引用Transform ALgorithm XPath 1.0: http ://www.w3.org/TR/1999/REC-xpath-19991116

当我用 xades4j 定义引用时,它看起来像这样:

DataObjectDesc ref1 = new DataObjectReference("")
                                    .withTransform(new XPathTransform(xpathValue).withNamespace(xpathNamespacePrefix, xpathNamespace))
                                    .withDataObjectFormat(new DataObjectFormatProperty("application/xml", "UTF-8").withDescription("xml dokumenta"));

我得到了在 xpath 中使用的函数 here() 未知的异常。Xpath 1.0 中未定义函数 here()。但是在示例 od UBL 签名的 xml 文件中,有:

<ds:Reference URI="">
    <ds:Transforms>
        <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
            <ds:XPath xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2">
                count(ancestor-or-self::sig:UBLDocumentSignatures | here()/ancestor::sig:UBLDocumentSignatures[1]) > count(ancestor-or-self::sig:UBLDocumentSignatures)
            </ds:XPath>
        </ds:Transform>
    </ds:Transforms>
    <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
    <ds:DigestValue>nLVnpwiT7Va0bsPgf14kso83NS8l+/usrd/a5l5ybeY=</ds:DigestValue>
</ds:Reference>

函数 here() 在 XML-Signature XPath Filter 2.0 中定义:https ://www.w3.org/TR/xmldsig-filter2/

我可以使用 xades4j 库使用函数 here() 进行参考变换吗???

最好的问候,约瑟普

标签: xpathxades4j

解决方案


学习规范后:

,我断定xades4j库有bug。

但是当我再次尝试执行我的代码以查看生成了什么异常堆栈时,我认为一切正常。

所以,我撤回这个问题。

约瑟普


推荐阅读