Search in sources :

Example 1 with SignaturePolicyInfoProvider

use of xades4j.providers.SignaturePolicyInfoProvider in project xades4j by luisgoncalves.

the class SignerEPESTest method testSignEPES.

@Test
public void testSignEPES() throws Exception {
    System.out.printf("signEPES: %s", locationUrl);
    System.out.println();
    Document doc = getTestDocument();
    Element elemToSign = doc.getDocumentElement();
    SignaturePolicyInfoProvider policyInfoProvider = new SignaturePolicyInfoProvider() {

        @Override
        public SignaturePolicyBase getSignaturePolicy() {
            return new SignaturePolicyIdentifierProperty(new ObjectIdentifier("oid:/1.2.4.0.9.4.5", IdentifierType.OIDAsURI, "Policy description"), new ByteArrayInputStream("Test policy input stream".getBytes())).withLocationUrl(locationUrl);
        }
    };
    SignerEPES signer = (SignerEPES) new XadesEpesSigningProfile(keyingProviderMy, policyInfoProvider).newSigner();
    new Enveloped(signer).sign(elemToSign);
    outputDocument(doc, output);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SignaturePolicyInfoProvider(xades4j.providers.SignaturePolicyInfoProvider) Element(org.w3c.dom.Element) SignaturePolicyIdentifierProperty(xades4j.properties.SignaturePolicyIdentifierProperty) Document(org.w3c.dom.Document) ObjectIdentifier(xades4j.properties.ObjectIdentifier) Test(org.junit.Test)

Example 2 with SignaturePolicyInfoProvider

use of xades4j.providers.SignaturePolicyInfoProvider in project xades4j by luisgoncalves.

the class SignerTTest method testSignTWithPolicy.

@Test
public void testSignTWithPolicy() throws Exception {
    System.out.println("signTWithPolicy");
    Document doc = getTestDocument();
    Element elemToSign = doc.getDocumentElement();
    SignerT signer = (SignerT) new XadesTSigningProfile(keyingProviderMy).withPolicyProvider(new SignaturePolicyInfoProvider() {

        @Override
        public SignaturePolicyBase getSignaturePolicy() {
            return new SignaturePolicyImpliedProperty();
        }
    }).newSigner();
    new Enveloped(signer).sign(elemToSign);
    outputDocument(doc, "document.signed.t.epes.xml");
}
Also used : SignaturePolicyBase(xades4j.properties.SignaturePolicyBase) SignaturePolicyInfoProvider(xades4j.providers.SignaturePolicyInfoProvider) Element(org.w3c.dom.Element) SignaturePolicyImpliedProperty(xades4j.properties.SignaturePolicyImpliedProperty) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 SignaturePolicyInfoProvider (xades4j.providers.SignaturePolicyInfoProvider)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectIdentifier (xades4j.properties.ObjectIdentifier)1 SignaturePolicyBase (xades4j.properties.SignaturePolicyBase)1 SignaturePolicyIdentifierProperty (xades4j.properties.SignaturePolicyIdentifierProperty)1 SignaturePolicyImpliedProperty (xades4j.properties.SignaturePolicyImpliedProperty)1