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


Java KeyAgreement.getProvider方法代碼示例

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


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

示例1: testKeyAgreementWithProvider

import javax.crypto.KeyAgreement; //導入方法依賴的package包/類
@Test
@Ignore
public void testKeyAgreementWithProvider() throws NoSuchAlgorithmException, NoSuchPaddingException {
    final String transformation = "DiffieHellman";
    final KeyAgreement expected = KeyAgreement.getInstance(transformation);
    final Provider expectedProvider = expected.getProvider();
    final KeyAgreement actual = convert(ProviderUtils.toArguments(transformation, expectedProvider));
    Assert.assertEquals(expected.getAlgorithm(), actual.getAlgorithm());
    Assert.assertEquals(expectedProvider, actual.getProvider());
}
 
開發者ID:garydgregory,項目名稱:jcommander-addons,代碼行數:11,代碼來源:KeyAgreementConverterTest.java

示例2: testDHKeyAgreementInterop

import javax.crypto.KeyAgreement; //導入方法依賴的package包/類
@Test
public void testDHKeyAgreementInterop()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidParameterSpecException, InvalidKeyException,
           InvalidAlgorithmParameterException {

    /* create DH params */
    AlgorithmParameterGenerator paramGen =
        AlgorithmParameterGenerator.getInstance("DH");
    paramGen.init(512);
    AlgorithmParameters params = paramGen.generateParameters();

    DHParameterSpec dhParams =
        (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);

    /* initialize key pair generator */
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH", "wolfJCE");
    keyGen.initialize(dhParams, new SecureRandom());

    KeyAgreement aKeyAgree = KeyAgreement.getInstance("DH", "wolfJCE");
    KeyAgreement bKeyAgree = KeyAgreement.getInstance("DH");

    Provider prov = bKeyAgree.getProvider();

    /* only run test if we have another provider besides ourselves */
    if (!prov.equals("wolfJCE")) {
        KeyPair aPair = keyGen.generateKeyPair();
        KeyPair bPair = keyGen.generateKeyPair();

        aKeyAgree.init(aPair.getPrivate());
        bKeyAgree.init(bPair.getPrivate());

        aKeyAgree.doPhase(bPair.getPublic(), true);
        bKeyAgree.doPhase(aPair.getPublic(), true);

        byte secretA[] = aKeyAgree.generateSecret();
        byte secretB[] = bKeyAgree.generateSecret();

        assertArrayEquals(secretA, secretB);

        /* now, try reusing the A object without calling init() again */
        KeyAgreement cKeyAgree = KeyAgreement.getInstance("DH", "wolfJCE");
        KeyPair cPair = keyGen.generateKeyPair();
        cKeyAgree.init(cPair.getPrivate());

        aKeyAgree.doPhase(cPair.getPublic(), true);
        cKeyAgree.doPhase(aPair.getPublic(), true);

        byte secretA2[] = aKeyAgree.generateSecret();
        byte secretC[]  = cKeyAgree.generateSecret();

        assertArrayEquals(secretA2, secretC);
    }
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:55,代碼來源:WolfCryptKeyAgreementTest.java

示例3: testECDHKeyAgreementInterop

import javax.crypto.KeyAgreement; //導入方法依賴的package包/類
@Test
public void testECDHKeyAgreementInterop()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidParameterSpecException, InvalidKeyException,
           InvalidAlgorithmParameterException {

    /* initialize key pair generator */
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC", "wolfJCE");
    ECGenParameterSpec ecsp = new ECGenParameterSpec("secp256r1");
    keyGen.initialize(ecsp);

    KeyAgreement aKeyAgree = KeyAgreement.getInstance("ECDH", "wolfJCE");
    KeyAgreement bKeyAgree = KeyAgreement.getInstance("ECDH");

    Provider prov = bKeyAgree.getProvider();
    if (prov.equals("wolfJCE")) {
        /* return, no other provider installed to interop against */
        return;
    }

    KeyPair aPair = keyGen.generateKeyPair();
    KeyPair bPair = keyGen.generateKeyPair();

    aKeyAgree.init(aPair.getPrivate());
    bKeyAgree.init(bPair.getPrivate());

    aKeyAgree.doPhase(bPair.getPublic(), true);
    bKeyAgree.doPhase(aPair.getPublic(), true);

    byte secretA[] = aKeyAgree.generateSecret();
    byte secretB[] = bKeyAgree.generateSecret();

    assertArrayEquals(secretA, secretB);

    /* now, try reusing the A object without calling init() again */
    KeyAgreement cKeyAgree =
        KeyAgreement.getInstance("ECDH", "wolfJCE");
    KeyPair cPair = keyGen.generateKeyPair();
    cKeyAgree.init(cPair.getPrivate());

    aKeyAgree.doPhase(cPair.getPublic(), true);
    cKeyAgree.doPhase(aPair.getPublic(), true);

    byte secretA2[] = aKeyAgree.generateSecret();
    byte secretC[]  = cKeyAgree.generateSecret();

    assertArrayEquals(secretA2, secretC);
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:49,代碼來源:WolfCryptKeyAgreementTest.java


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