use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method test_getProvider.
public void test_getProvider() throws NoSuchAlgorithmException {
KeyAgreement keyA;
for (int i = 0; i < validValues.length; i++) {
keyA = KeyAgreement.getInstance(validValues[i]);
assertNotNull(keyA.getProvider());
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method testInit04.
/**
* Test for the methods:
* <code>init(Key key, AlgorithmParameterSpec params)</code>
* <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code>
* <code>generateSecret()</code>
* Assertions: initializes KeyAgreement and returns byte array
*/
public void testInit04() throws Exception, InvalidAlgorithmParameterException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
DHParameterSpec dhPs = ((DHPrivateKey) privKey).getParams();
AlgorithmParameterSpec aps = new RSAKeyGenParameterSpec(10, new BigInteger("10"));
byte[] bbRes1;
byte[] bbRes2;
byte[] bbRes3;
SecureRandom randomNull = null;
SecureRandom random = new SecureRandom();
for (int i = 0; i < kAgs.length; i++) {
kAgs[i].init(privKey, dhPs);
kAgs[i].doPhase(publKey, true);
bbRes1 = kAgs[i].generateSecret();
kAgs[i].init(privKey, dhPs, random);
kAgs[i].doPhase(publKey, true);
bbRes2 = kAgs[i].generateSecret();
assertEquals("Incorrect byte array length", bbRes1.length, bbRes2.length);
for (int j = 0; j < bbRes1.length; j++) {
assertEquals("Incorrect byte (index: ".concat(Integer.toString(i)).concat(")"), bbRes1[j], bbRes2[j]);
}
kAgs[i].init(privKey, dhPs, randomNull);
kAgs[i].doPhase(publKey, true);
bbRes3 = kAgs[i].generateSecret();
assertEquals("Incorrect byte array length", bbRes1.length, bbRes3.length);
for (int j = 0; j < bbRes1.length; j++) {
assertEquals("Incorrect byte (index: ".concat(Integer.toString(i)).concat(")"), bbRes1[j], bbRes3[j]);
}
try {
kAgs[i].init(publKey, dhPs, random);
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
try {
kAgs[i].init(privKey, aps, random);
fail("InvalidAlgorithmParameterException expected");
} catch (InvalidAlgorithmParameterException e) {
//expected
}
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method test_initLjava_security_KeyLjava_security_SecureRandom.
public void test_initLjava_security_KeyLjava_security_SecureRandom() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(privKey, new SecureRandom());
try {
ka.init(publKey, new SecureRandom());
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method test_generateSecretLjava_lang_String.
public void test_generateSecretLjava_lang_String() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
KeyAgreement ka = KeyAgreement.getInstance("DH");
byte[] bb1 = new byte[1];
try {
ka.generateSecret("dh");
fail("IllegalStateException expected");
} catch (IllegalStateException e) {
//expected
}
ka.init(privKey);
ka.doPhase(publKey, true);
try {
ka.generateSecret("Wrong alg name");
fail("NoSuchAlgorithmException expected");
} catch (NoSuchAlgorithmException e) {
//expected
}
}
use of javax.crypto.KeyAgreement in project robovm by robovm.
the class KeyAgreementTest method testGetInstanceString02.
/**
* Test for <code> getInstance(String algorithm) </code> method Assertions:
* returns KeyAgreement object
*/
public void testGetInstanceString02() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyAgreement keyA;
for (int i = 0; i < validValues.length; i++) {
keyA = KeyAgreement.getInstance(validValues[i]);
assertEquals("Incorrect algorithm", keyA.getAlgorithm(), validValues[i]);
}
}
Aggregations