Java Code Examples for java.security.MessageDigest.getProvider()

The following are Jave code examples for showing how to use getProvider() of the java.security.MessageDigest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: wolfcrypt-jni   File: WolfCryptMessageDigestSha256Test.java   View Source Code Vote up 4 votes
@Test
public void testSha256Interop()
    throws NoSuchProviderException, NoSuchAlgorithmException {

    String input = "Bozeman, MT";
    String input2 = "wolfSSL is an Open Source Internet security " +
                    "company, focused primarily on SSL/TLS and " +
                    "cryptography. Main products include the wolfSSL " +
                    "embedded SSL/TLS library, wolfCrypt cryptography " +
                    "library, wolfMQTT, and wolfSSH. Products are " +
                    "dual licensed under both GPLv2 and a commercial" +
                    "license.";

    byte[] wolfOutput;
    byte[] interopOutput;

    MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
    Provider provider = sha256.getProvider();

    /* if we have another MessageDigest provider, test against it */
    if (!provider.equals("wolfJCE")) {

        /* short message */
        sha256.update(input.getBytes());
        interopOutput = sha256.digest();

        MessageDigest wolfSha256 =
            MessageDigest.getInstance("SHA-256", "wolfJCE");

        wolfSha256.update(input.getBytes());
        wolfOutput = wolfSha256.digest();

        assertArrayEquals(wolfOutput, interopOutput);

        /* long message */
        sha256.update(input2.getBytes());
        interopOutput = sha256.digest();

        wolfSha256.update(input2.getBytes());
        wolfOutput = wolfSha256.digest();

        assertArrayEquals(wolfOutput, interopOutput);
    }
}
 
Example 2
Project: wolfcrypt-jni   File: WolfCryptMessageDigestMd5Test.java   View Source Code Vote up 4 votes
@Test
public void testMd5Interop()
    throws NoSuchProviderException, NoSuchAlgorithmException {

    String input = "Bozeman, MT";
    String input2 = "wolfSSL is an Open Source Internet security " +
                    "company, focused primarily on SSL/TLS and " +
                    "cryptography. Main products include the wolfSSL " +
                    "embedded SSL/TLS library, wolfCrypt cryptography " +
                    "library, wolfMQTT, and wolfSSH. Products are " +
                    "dual licensed under both GPLv2 and a commercial" +
                    "license.";

    byte[] wolfOutput;
    byte[] interopOutput;

    MessageDigest md5 = MessageDigest.getInstance("MD5");
    Provider provider = md5.getProvider();

    /* if we have another MessageDigest provider, test against it */
    if (!provider.equals("wolfJCE")) {

        /* short message */
        md5.update(input.getBytes());
        interopOutput = md5.digest();

        MessageDigest wolfMd5 =
            MessageDigest.getInstance("MD5", "wolfJCE");

        wolfMd5.update(input.getBytes());
        wolfOutput = wolfMd5.digest();

        assertArrayEquals(wolfOutput, interopOutput);

        /* long message */
        md5.update(input2.getBytes());
        interopOutput = md5.digest();

        wolfMd5.update(input2.getBytes());
        wolfOutput = wolfMd5.digest();

        assertArrayEquals(wolfOutput, interopOutput);
    }
}
 
Example 3
Project: wolfcrypt-jni   File: WolfCryptMessageDigestSha384Test.java   View Source Code Vote up 4 votes
@Test
public void testSha384Interop()
    throws NoSuchProviderException, NoSuchAlgorithmException {

    String input = "Bozeman, MT";
    String input2 = "wolfSSL is an Open Source Internet security " +
                    "company, focused primarily on SSL/TLS and " +
                    "cryptography. Main products include the wolfSSL " +
                    "embedded SSL/TLS library, wolfCrypt cryptography " +
                    "library, wolfMQTT, and wolfSSH. Products are " +
                    "dual licensed under both GPLv2 and a commercial" +
                    "license.";

    byte[] wolfOutput;
    byte[] interopOutput;

    MessageDigest sha384 = MessageDigest.getInstance("SHA-384");
    Provider provider = sha384.getProvider();

    /* if we have another MessageDigest provider, test against it */
    if (!provider.equals("wolfJCE")) {

        /* short message */
        sha384.update(input.getBytes());
        interopOutput = sha384.digest();

        MessageDigest wolfSha384 =
            MessageDigest.getInstance("SHA-384", "wolfJCE");

        wolfSha384.update(input.getBytes());
        wolfOutput = wolfSha384.digest();

        assertArrayEquals(wolfOutput, interopOutput);

        /* long message */
        sha384.update(input2.getBytes());
        interopOutput = sha384.digest();

        wolfSha384.update(input2.getBytes());
        wolfOutput = wolfSha384.digest();

        assertArrayEquals(wolfOutput, interopOutput);
    }

}
 
Example 4
Project: wolfcrypt-jni   File: WolfCryptMessageDigestShaTest.java   View Source Code Vote up 4 votes
@Test
public void testShaInterop()
    throws NoSuchProviderException, NoSuchAlgorithmException {

    String input = "Bozeman, MT";
    String input2 = "wolfSSL is an Open Source Internet security " +
                    "company, focused primarily on SSL/TLS and " +
                    "cryptography. Main products include the wolfSSL " +
                    "embedded SSL/TLS library, wolfCrypt cryptography " +
                    "library, wolfMQTT, and wolfSSH. Products are " +
                    "dual licensed under both GPLv2 and a commercial" +
                    "license.";

    byte[] wolfOutput;
    byte[] interopOutput;

    MessageDigest sha = MessageDigest.getInstance("SHA-1");
    Provider provider = sha.getProvider();

    /* if we have another MessageDigest provider, test against it */
    if (!provider.equals("wolfJCE")) {

        /* short message */
        sha.update(input.getBytes());
        interopOutput = sha.digest();

        MessageDigest wolfSha =
            MessageDigest.getInstance("SHA-1", "wolfJCE");

        wolfSha.update(input.getBytes());
        wolfOutput = wolfSha.digest();

        assertArrayEquals(wolfOutput, interopOutput);

        /* long message */
        sha.update(input2.getBytes());
        interopOutput = sha.digest();

        wolfSha.update(input2.getBytes());
        wolfOutput = wolfSha.digest();

        assertArrayEquals(wolfOutput, interopOutput);
    }
}
 
Example 5
Project: wolfcrypt-jni   File: WolfCryptMessageDigestSha512Test.java   View Source Code Vote up 4 votes
@Test
public void testSha512Interop()
    throws NoSuchProviderException, NoSuchAlgorithmException {

    String input = "Bozeman, MT";
    String input2 = "wolfSSL is an Open Source Internet security " +
                    "company, focused primarily on SSL/TLS and " +
                    "cryptography. Main products include the wolfSSL " +
                    "embedded SSL/TLS library, wolfCrypt cryptography " +
                    "library, wolfMQTT, and wolfSSH. Products are " +
                    "dual licensed under both GPLv2 and a commercial" +
                    "license.";

    byte[] wolfOutput;
    byte[] interopOutput;

    MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
    Provider provider = sha512.getProvider();

    /* if we have another MessageDigest provider, test against it */
    if (!provider.equals("wolfJCE")) {

        /* short message */
        sha512.update(input.getBytes());
        interopOutput = sha512.digest();

        MessageDigest wolfSha512 =
            MessageDigest.getInstance("SHA-512", "wolfJCE");

        wolfSha512.update(input.getBytes());
        wolfOutput = wolfSha512.digest();

        assertArrayEquals(wolfOutput, interopOutput);

        /* long message */
        sha512.update(input2.getBytes());
        interopOutput = sha512.digest();

        wolfSha512.update(input2.getBytes());
        wolfOutput = wolfSha512.digest();

        assertArrayEquals(wolfOutput, interopOutput);
    }

}
 
Example 6
Project: openjdk-jdk10   File: TestSameValue.java   View Source Code Vote up 4 votes
private void run() throws Exception {

        byte[] data = new byte[6706];
        MessageDigest md = null;
        // Initialize input data
        RandomFactory.getRandom().nextBytes(data);

        String[] algorithmArr = { "SHA", "Sha", "MD5", "md5", "SHA-224",
                "SHA-256", "SHA-384", "SHA-512", "SHA3-224", "SHA3-256",
                "SHA3-384", "SHA3-512" };

        for (String algorithm : algorithmArr) {
            try {
                md = MessageDigest.getInstance(algorithm);

                for (UpdateDigestMethod updateMethod : UpdateDigestMethod
                        .values()) {
                    byte[] output = updateMethod.updateDigest(data, md);
                    // Get the output and the "correct" one
                    byte[] standard = md.digest(data);
                    // Compare input and output
                    if (!MessageDigest.isEqual(output, standard)) {
                        throw new RuntimeException(
                                "Test failed at algorithm/provider/numUpdate:"
                                        + algorithm + "/" + md.getProvider()
                                        + "/" + updateMethod);
                    }
                }
            } catch (NoSuchAlgorithmException nae) {
                if (algorithm.startsWith("SHA3") && !isSHA3supported()) {
                    continue;
                } else {
                    throw nae;
                }
            }
        }

        out.println("All "
                + algorithmArr.length * UpdateDigestMethod.values().length
                + " tests Passed");
    }