本文整理汇总了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());
}
示例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);
}
}
示例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);
}