當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageDigest.getProvider方法代碼示例

本文整理匯總了Java中java.security.MessageDigest.getProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageDigest.getProvider方法的具體用法?Java MessageDigest.getProvider怎麽用?Java MessageDigest.getProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.MessageDigest的用法示例。


在下文中一共展示了MessageDigest.getProvider方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSha256Interop

import java.security.MessageDigest; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:45,代碼來源:WolfCryptMessageDigestSha256Test.java

示例2: testMd5Interop

import java.security.MessageDigest; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:45,代碼來源:WolfCryptMessageDigestMd5Test.java

示例3: testSha384Interop

import java.security.MessageDigest; //導入方法依賴的package包/類
@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);
    }

}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:46,代碼來源:WolfCryptMessageDigestSha384Test.java

示例4: testShaInterop

import java.security.MessageDigest; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:45,代碼來源:WolfCryptMessageDigestShaTest.java

示例5: testSha512Interop

import java.security.MessageDigest; //導入方法依賴的package包/類
@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);
    }

}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:46,代碼來源:WolfCryptMessageDigestSha512Test.java

示例6: run

import java.security.MessageDigest; //導入方法依賴的package包/類
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");
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:TestSameValue.java


注:本文中的java.security.MessageDigest.getProvider方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。