当前位置: 首页>>代码示例>>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;未经允许,请勿转载。