Search in sources :

Example 1 with XMLCryptoContext

use of javax.xml.crypto.XMLCryptoContext in project wildfly by wildfly.

the class TestServlet method validateSignature.

private static boolean validateSignature(final Document document, final PublicKey publicKey) throws Exception {
    final KeySelector ks = new KeySelector() {

        @Override
        public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
            return new KeySelectorResult() {

                public Key getKey() {
                    return publicKey;
                }
            };
        }
    };
    final DOMValidateContext context = new DOMValidateContext(ks, document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0));
    return XMLSignatureFactory.getInstance("DOM").unmarshalXMLSignature(context).validate(context);
}
Also used : KeyInfo(javax.xml.crypto.dsig.keyinfo.KeyInfo) DOMValidateContext(javax.xml.crypto.dsig.dom.DOMValidateContext) XMLCryptoContext(javax.xml.crypto.XMLCryptoContext) AlgorithmMethod(javax.xml.crypto.AlgorithmMethod) KeySelectorResult(javax.xml.crypto.KeySelectorResult) KeySelector(javax.xml.crypto.KeySelector)

Aggregations

AlgorithmMethod (javax.xml.crypto.AlgorithmMethod)1 KeySelector (javax.xml.crypto.KeySelector)1 KeySelectorResult (javax.xml.crypto.KeySelectorResult)1 XMLCryptoContext (javax.xml.crypto.XMLCryptoContext)1 DOMValidateContext (javax.xml.crypto.dsig.dom.DOMValidateContext)1 KeyInfo (javax.xml.crypto.dsig.keyinfo.KeyInfo)1