use of org.apache.xml.security.utils.resolver.implementations.ResolverXPointer in project santuario-java by apache.
the class SignatureTest method signDocument.
private XMLSignature signDocument(Document doc) throws Throwable {
XMLSignature sig = new XMLSignature(doc, "", XMLSignature.ALGO_ID_SIGNATURE_DSA);
Element root = doc.getDocumentElement();
root.appendChild(sig.getElement());
sig.getSignedInfo().addResourceResolver(new ResolverXPointer());
Transforms transforms = new Transforms(doc);
transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
sig.addKeyInfo(getPublicKey());
sig.sign(getPrivateKey());
return sig;
}
use of org.apache.xml.security.utils.resolver.implementations.ResolverXPointer in project verify-hub by alphagov.
the class BuilderHelper method createXMLSignature.
public static XMLSignature createXMLSignature(final SignatureAlgorithm signatureAlgorithm, final DigestAlgorithm digestAlgorithm) {
DocumentBuilder documentBuilder = null;
XMLSignature xmlSignature = null;
try {
documentBuilder = XMLUtils.createDocumentBuilder(false);
} catch (ParserConfigurationException e) {
}
Document doc = documentBuilder.newDocument();
Element rootElement = doc.createElementNS("https://www.verify.gov.uk/", "root");
rootElement.appendChild(doc.createTextNode("Welcome to Verify GOV.UK!"));
doc.appendChild(rootElement);
try {
xmlSignature = new XMLSignature(doc, "", signatureAlgorithm.getURI());
Element root = doc.getDocumentElement();
root.appendChild(xmlSignature.getElement());
xmlSignature.getSignedInfo().addResourceResolver(new ResolverXPointer());
Transforms transforms = new Transforms(doc);
transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
xmlSignature.addDocument("", transforms, digestAlgorithm.getURI());
} catch (org.apache.xml.security.exceptions.XMLSecurityException e) {
}
return xmlSignature;
}
use of org.apache.xml.security.utils.resolver.implementations.ResolverXPointer in project santuario-java by apache.
the class SignatureReferenceTest method signDocument.
private XMLSignature signDocument(Document doc) throws Throwable {
XMLSignature sig = new XMLSignature(doc, "", XMLSignature.ALGO_ID_SIGNATURE_DSA);
Element root = doc.getDocumentElement();
root.appendChild(sig.getElement());
sig.getSignedInfo().addResourceResolver(new ResolverXPointer());
Transforms transforms = new Transforms(doc);
transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
sig.addKeyInfo(getPublicKey());
sig.sign(getPrivateKey());
return sig;
}
Aggregations