58,454
社区成员
发帖
与我相关
我的任务
分享
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "");
trans.setOutputProperty(OutputKeys.ENCODING,"UTF-8");
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.transform(new DOMSource(doc), new StreamResult(os));
<?xml version="1.0" encoding="UTF-8"?>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#object">
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>iDhYt78o294fA6pzQ7k44+eejrQMi+WX3l3UrUdtL1Q=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>OfLkwi626j8aoLrSTvl36kDSTAENo787hnOCUcCVpKZPXFaOsiQ0G19pQ30mEA908tEe99OYdOfg
bN96Z7EymDyiUjXnVtme0Y9U7wXYBbK6FdQb5vnmYTOPDt2DHFfA9hqN5X7P6GfHF9JEQHHpTHS8
nDGokbsvGyrLojvYDlY=</SignatureValue>
<KeyInfo>
<KeyValue>
<RSAKeyValue>
<Modulus>0F2AiQfHDyR0SdStp0VlP9JOsSq7xUUs8khdncwXTsF3dHqZi+92g34wvvlP8kunx9TDq/kmssWd
Z/hUtjGxQhT3TX8Cbybrds2cAGoD2cdNnjoUwvzOchJHLL5SYHFQB7PZSSmBrmAV3xTKbtAq57m6
XUHJmkjZwA9SjoFComc=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
<Object Id="object">some text</Object>
</Signature>