Search in sources :

Example 1 with XMLSignature

use of com.sun.org.apache.xml.internal.security.signature.XMLSignature in project jdk8u_jdk by JetBrains.

the class TruncateHMAC method generate_hmac_sha1_40.

private static void generate_hmac_sha1_40() throws Exception {
    System.out.println("Generating ");
    Document doc = dbf.newDocumentBuilder().newDocument();
    XMLSignature sig = new XMLSignature(doc, null, XMLSignature.ALGO_ID_MAC_HMAC_SHA1, 40, Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    try {
        sig.sign(getSecretKey("secret".getBytes("ASCII")));
        System.out.println("FAILED");
        atLeastOneFailed = true;
    } catch (XMLSignatureException xse) {
        System.out.println(xse.getMessage());
        System.out.println("PASSED");
    }
}
Also used : XMLSignature(com.sun.org.apache.xml.internal.security.signature.XMLSignature) Document(org.w3c.dom.Document) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Example 2 with XMLSignature

use of com.sun.org.apache.xml.internal.security.signature.XMLSignature in project jdk8u_jdk by JetBrains.

the class TruncateHMAC method validate.

private static void validate(String data, boolean pass) throws Exception {
    System.out.println("Validating " + data);
    File file = new File(DIR, data);
    Document doc = dbf.newDocumentBuilder().parse(file);
    NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
    if (nl.getLength() == 0) {
        throw new Exception("Couldn't find signature Element");
    }
    Element sigElement = (Element) nl.item(0);
    XMLSignature signature = new XMLSignature(sigElement, file.toURI().toString());
    SecretKey sk = signature.createSecretKey("secret".getBytes("ASCII"));
    try {
        System.out.println("Validation status: " + signature.checkSignatureValue(sk));
        if (!pass) {
            System.out.println("FAILED");
            atLeastOneFailed = true;
        } else {
            System.out.println("PASSED");
        }
    } catch (XMLSignatureException xse) {
        System.out.println(xse.getMessage());
        if (!pass) {
            System.out.println("PASSED");
        } else {
            System.out.println("FAILED");
            atLeastOneFailed = true;
        }
    }
}
Also used : SecretKey(javax.crypto.SecretKey) XMLSignature(com.sun.org.apache.xml.internal.security.signature.XMLSignature) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Aggregations

XMLSignature (com.sun.org.apache.xml.internal.security.signature.XMLSignature)2 XMLSignatureException (com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)2 Document (org.w3c.dom.Document)2 File (java.io.File)1 SecretKey (javax.crypto.SecretKey)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1