Search in sources :

Example 6 with MessageDigestAlgorithm

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

the class DigestAlgorithmTest method testSHA3_384.

@org.junit.Test
public void testSHA3_384() throws Exception {
    org.junit.Assume.assumeTrue(bcInstalled);
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_384);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_384, 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("SHA3-384");
    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 7 with MessageDigestAlgorithm

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

the class DigestAlgorithmTest method testSHA512.

@org.junit.Test
public void testSHA512() throws Exception {
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA512);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA512, 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-512");
    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 8 with MessageDigestAlgorithm

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

the class DigestAlgorithmTest method testSHA3_512.

@org.junit.Test
public void testSHA3_512() throws Exception {
    org.junit.Assume.assumeTrue(bcInstalled);
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_512);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_512, 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("SHA3-512");
    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 9 with MessageDigestAlgorithm

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

the class DigestAlgorithmTest method testWhirlpool.

@org.junit.Test
public void testWhirlpool() throws Exception {
    org.junit.Assume.assumeTrue(bcInstalled);
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_WHIRLPOOL);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_WHIRLPOOL, 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("WHIRLPOOL");
    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 10 with MessageDigestAlgorithm

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

the class DigestAlgorithmTest method testSHA3_224.

@org.junit.Test
public void testSHA3_224() throws Exception {
    org.junit.Assume.assumeTrue(bcInstalled);
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    MessageDigestAlgorithm digestAlgorithm = MessageDigestAlgorithm.getInstance(doc, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_224);
    assertEquals(MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA3_224, 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("SHA3-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)

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