xades4j : 如何创建-T
用到哪些类,对应哪些元素
xades4j.properties.UnsignedProperties
xades4j.properties.UnsignedSignatureProperty
xades4j.properties.SignatureTimeStampProperty
具体实现
import java.util.ArrayList; import java.util.Collection; import org.apache.xml.security.signature.XMLSignature; import org.apache.xml.security.utils.Constants; import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import xades4j.properties.SignatureTimeStampProperty; import xades4j.properties.UnsignedProperties; import xades4j.properties.UnsignedSignatureProperty;
@Test public void testEnrichSignatureWithT() throws Exception { System.out.println("enrichSignatureWithT"); // 1)取得xades-bes Document doc = getDocument("document.signed.bes.xml"); // 2)取得 sinature 部分 Element signatureNode = (Element) doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature").item(0); XMLSignature signature = new XMLSignature(signatureNode, ""); // 3) 封装 signatureTimeStamp -> unsignedSignatureProperties -> // unsignedProperties SignatureTimeStampProperty signatureTimeStamp = new SignatureTimeStampProperty(); Collection<UnsignedSignatureProperty> unsignedSignatureProperties = new ArrayList<UnsignedSignatureProperty>(1); unsignedSignatureProperties.add(signatureTimeStamp); UnsignedProperties unsignedProperties = new UnsignedProperties(unsignedSignatureProperties); // 改变前 outputDocument(doc, "document.signed.bes.unenriched.t.xml"); // 4)change XadesSignatureFormatExtenderImpl formatExtender = (XadesSignatureFormatExtenderImpl) new XadesFormatExtenderProfile() .getFormatExtender(); formatExtender.enrichSignature(signature, unsignedProperties); // 改变后 outputDocument(doc, "document.signed.bes.enriched.t.xml"); }
结果对比
vs