Search in sources :

Example 6 with DataObjectFormatProperty

use of xades4j.properties.DataObjectFormatProperty in project xades4j by luisgoncalves.

the class SignerBESTest method testSignBES.

@Test
public void testSignBES() throws Exception {
    System.out.println("signBES");
    Document doc1 = getTestDocument();
    Document doc2 = getDocument("content.xml");
    Node objectContent = doc1.importNode(doc2.getDocumentElement(), true);
    Element elemToSign = doc1.getDocumentElement();
    SignerBES signer = (SignerBES) new XadesBesSigningProfile(keyingProviderMy).newSigner();
    IndividualDataObjsTimeStampProperty dataObjsTimeStamp = new IndividualDataObjsTimeStampProperty();
    AllDataObjsCommitmentTypeProperty globalCommitment = AllDataObjsCommitmentTypeProperty.proofOfApproval();
    CommitmentTypeProperty commitment = (CommitmentTypeProperty) CommitmentTypeProperty.proofOfCreation().withQualifier("MyQualifier");
    DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id")).withTransform(new EnvelopedSignatureTransform()).withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding").withDescription("Isto é uma descrição do elemento raiz").withDocumentationUri("http://doc1.txt").withDocumentationUri("http://doc2.txt").withIdentifier("http://elem.root")).withCommitmentType(commitment).withDataObjectTimeStamp(dataObjsTimeStamp);
    DataObjectDesc obj2 = new EnvelopedXmlObject(objectContent, "text/xml", null).withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding").withDescription("Isto é uma descrição do elemento dentro do object").withDocumentationUri("http://doc3.txt").withDocumentationUri("http://doc4.txt").withIdentifier("http://elem.in.object")).withCommitmentType(commitment).withDataObjectTimeStamp(dataObjsTimeStamp);
    SignedDataObjects dataObjs = new SignedDataObjects(obj1, obj2).withCommitmentType(globalCommitment).withDataObjectsTimeStamp();
    signer.sign(dataObjs, elemToSign);
    outputDocument(doc1, "document.signed.bes.xml");
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) DataObjectFormatProperty(xades4j.properties.DataObjectFormatProperty) EnvelopedSignatureTransform(xades4j.algorithms.EnvelopedSignatureTransform) Document(org.w3c.dom.Document) DataObjectDesc(xades4j.properties.DataObjectDesc) AllDataObjsCommitmentTypeProperty(xades4j.properties.AllDataObjsCommitmentTypeProperty) AllDataObjsCommitmentTypeProperty(xades4j.properties.AllDataObjsCommitmentTypeProperty) CommitmentTypeProperty(xades4j.properties.CommitmentTypeProperty) IndividualDataObjsTimeStampProperty(xades4j.properties.IndividualDataObjsTimeStampProperty) Test(org.junit.Test)

Aggregations

DataObjectFormatProperty (xades4j.properties.DataObjectFormatProperty)6 Test (org.junit.Test)4 DataObjectDesc (xades4j.properties.DataObjectDesc)4 Document (org.w3c.dom.Document)3 IndividualDataObjsTimeStampProperty (xades4j.properties.IndividualDataObjsTimeStampProperty)3 AllDataObjsCommitmentTypeProperty (xades4j.properties.AllDataObjsCommitmentTypeProperty)2 CommitmentTypeProperty (xades4j.properties.CommitmentTypeProperty)2 SigningTimeProperty (xades4j.properties.SigningTimeProperty)2 TypeLiteral (com.google.inject.TypeLiteral)1 File (java.io.File)1 ObjectContainer (org.apache.xml.security.signature.ObjectContainer)1 Reference (org.apache.xml.security.signature.Reference)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 EnvelopedSignatureTransform (xades4j.algorithms.EnvelopedSignatureTransform)1 XPathTransform (xades4j.algorithms.XPathTransform)1 AllDataObjsTimeStampProperty (xades4j.properties.AllDataObjsTimeStampProperty)1 ArchiveTimeStampProperty (xades4j.properties.ArchiveTimeStampProperty)1 CertificateValuesProperty (xades4j.properties.CertificateValuesProperty)1 CompleteCertificateRefsProperty (xades4j.properties.CompleteCertificateRefsProperty)1