use of javax.crypto.KeyAgreement in project error-prone by google.
the class InsecureCipherModeNegativeCases method ellipticCurveDiffieHellman.
public void ellipticCurveDiffieHellman() {
KeyFactory keyFactory;
KeyAgreement keyAgreement;
KeyPairGenerator keyPairGenerator;
final String ecdh = "ECDH";
try {
keyFactory = KeyFactory.getInstance(ecdh);
keyAgreement = KeyAgreement.getInstance("ECDH");
keyPairGenerator = KeyPairGenerator.getInstance("EC" + "DH");
} catch (NoSuchAlgorithmException e) {
// We don't handle any exception as this code is not meant to be executed.
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method testInit02.
/**
* Test for the methods
* <code>init(Key key, AlgorithmParameterSpec params)</code>
* <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code>
* Assertion: throws AlgorithmParameterException when params are
* inappropriate
*/
public void testInit02() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
SecureRandom random = null;
DSAParameterSpec dsa = new DSAParameterSpec(new BigInteger("56"), new BigInteger("56"), new BigInteger("56"));
for (int i = 0; i < kAgs.length; i++) {
try {
kAgs[i].init(privKey, dsa);
fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw");
} catch (InvalidAlgorithmParameterException e) {
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(privKey, dsa, new SecureRandom());
fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw");
} catch (InvalidAlgorithmParameterException e) {
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(privKey, dsa, random);
fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw");
} catch (InvalidAlgorithmParameterException e) {
} catch (InvalidKeyException e) {
}
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method testGetInstanceStringProvider03.
/**
* Test for <code> getInstance(String algorithm, Provider provider)</code>
* method Assertions: returns KeyAgreement object
*/
public void testGetInstanceStringProvider03() throws IllegalArgumentException, NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyAgreement keyA;
for (int i = 0; i < validValues.length; i++) {
keyA = KeyAgreement.getInstance(validValues[i], defaultProvider);
assertEquals("Incorrect algorithm", keyA.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", keyA.getProvider(), defaultProvider);
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method test_getAlgorithm.
public void test_getAlgorithm() throws NoSuchAlgorithmException {
Mock_KeyAgreement mka = new Mock_KeyAgreement(null, null, null);
assertNull(mka.getAlgorithm());
KeyAgreement keyA;
for (int i = 0; i < validValues.length; i++) {
keyA = KeyAgreement.getInstance(validValues[i]);
assertEquals("Incorrect algorithm", keyA.getAlgorithm(), validValues[i]);
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method testInit01.
/**
* Test for the methods <code>init(Key key)</code>
* <code>init(Key key, SecureRandom random)</code>
* <code>init(Key key, AlgorithmParameterSpec params)</code>
* <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code>
* Assertion: throws InvalidKeyException when key is inappropriate
*/
public void testInit01() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
SecureRandom random = null;
AlgorithmParameterSpec aps = null;
DHParameterSpec dhPs = new DHParameterSpec(new BigInteger("56"), new BigInteger("56"));
for (int i = 0; i < kAgs.length; i++) {
try {
kAgs[i].init(publKey);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, new SecureRandom());
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, random);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, dhPs);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, aps);
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
try {
kAgs[i].init(publKey, dhPs, new SecureRandom());
fail("InvalidKeyException must be throw");
} catch (InvalidKeyException e) {
}
}
}
Aggregations