Search in sources :

Example 11 with MessageDigestAlgorithm

use of org.apache.xml.security.algorithms.MessageDigestAlgorithm in project santuario-java by apache.

the class DigestAlgorithmTest method testSHA1.

@org.junit.Test
public void testSHA1() throws Exception {
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1, digestAlgorithm.getAlgorithmURI());
    byte[] digest = digestAlgorithm.digest("test-string".getBytes());
    assertNotNull(digest);
    assertTrue(digest.length > 0);
    // Now compare against a JDK MessageDigest Object
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    byte[] digest2 = md.digest("test-string".getBytes());
    assertTrue(Arrays.equals(digest, digest2));
}
Also used : MessageDigestAlgorithm(org.apache.xml.security.algorithms.MessageDigestAlgorithm) Document(org.w3c.dom.Document) MessageDigest(java.security.MessageDigest)

Example 12 with MessageDigestAlgorithm

use of org.apache.xml.security.algorithms.MessageDigestAlgorithm in project santuario-java by apache.

the class DigestAlgorithmTest method testSHA224.

@org.junit.Test
public void testSHA224() throws Exception {
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA224, digestAlgorithm.getAlgorithmURI());
    byte[] digest = digestAlgorithm.digest("test-string".getBytes());
    assertNotNull(digest);
    assertTrue(digest.length > 0);
    // Now compare against a JDK MessageDigest Object
    MessageDigest md = MessageDigest.getInstance("SHA-224");
    byte[] digest2 = md.digest("test-string".getBytes());
    assertTrue(Arrays.equals(digest, digest2));
}
Also used : MessageDigestAlgorithm(org.apache.xml.security.algorithms.MessageDigestAlgorithm) Document(org.w3c.dom.Document) MessageDigest(java.security.MessageDigest)

Example 13 with MessageDigestAlgorithm

use of org.apache.xml.security.algorithms.MessageDigestAlgorithm in project santuario-java by apache.

the class DigestAlgorithmTest method testRIPEMD160.

@org.junit.Test
public void testRIPEMD160() throws Exception {
    org.junit.Assume.assumeTrue(bcInstalled);
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_RIPEMD160);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_RIPEMD160, digestAlgorithm.getAlgorithmURI());
    byte[] digest = digestAlgorithm.digest("test-string".getBytes());
    assertNotNull(digest);
    assertTrue(digest.length > 0);
    // Now compare against a JDK MessageDigest Object
    MessageDigest md = MessageDigest.getInstance("RIPEMD160");
    byte[] digest2 = md.digest("test-string".getBytes());
    assertTrue(Arrays.equals(digest, digest2));
}
Also used : MessageDigestAlgorithm(org.apache.xml.security.algorithms.MessageDigestAlgorithm) Document(org.w3c.dom.Document) MessageDigest(java.security.MessageDigest)

Aggregations

MessageDigestAlgorithm (org.apache.xml.security.algorithms.MessageDigestAlgorithm)13 MessageDigest (java.security.MessageDigest)12 Document (org.w3c.dom.Document)12 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 Transforms (org.apache.xml.security.transforms.Transforms)1 DigesterOutputStream (org.apache.xml.security.utils.DigesterOutputStream)1 UnsyncBufferedOutputStream (org.apache.xml.security.utils.UnsyncBufferedOutputStream)1