在java中将属性添加到签名xml

时间:2015-06-08 15:47:05

标签: xml digital-signature

我需要使用java为我的签名XML块中的根元素添加ID属性。这是当前的签名XML文件:

<ds:Signature>
<ds:SignedInfo>
    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <ds:Reference URI="">
        <ds:Transforms>
            <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
        </ds:Transforms>
        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
        <ds:DigestValue>36FmAjgxR3feEHGoblPJz1IWyTM=</ds:DigestValue>
    </ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>...</ds:SignatureValue>
<ds:KeyInfo>
    <ds:X509Data>
        <ds:X509SubjectName>...</ds:X509SubjectName>
        <ds:X509Certificate>...</ds:X509Certificate>
    </ds:X509Data>
</ds:KeyInfo>

但我需要添加一个属性:

<ds:Signature ID="SOMETHING">

1 个答案:

答案 0 :(得分:1)

解决方案

XMLSignature signature = fac.newXMLSignature(si,Ki,null,&#34; SignST&#34;,null);