use of java.security.AlgorithmParameterGenerator in project robovm by robovm.
the class AlgorithmParameterGenerator2Test method testGetInstance03.
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code>
* method
* Assertions:
* throws NullPointerException must be thrown is null
* throws NoSuchAlgorithmException must be thrown if algorithm is not available
* throws IllegalArgumentException when provider is null;
* returns AlgorithmParameterGenerator object
*/
public void testGetInstance03() throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException {
try {
AlgorithmParameterGenerator.getInstance(null, mProv);
fail("NullPointerException or NoSuchAlgorithmException should be thrown");
} catch (NullPointerException e) {
} catch (NoSuchAlgorithmException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
AlgorithmParameterGenerator.getInstance(invalidValues[i], mProv);
fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
Provider prov = null;
for (int i = 0; i < validValues.length; i++) {
try {
AlgorithmParameterGenerator.getInstance(validValues[i], prov);
fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
}
AlgorithmParameterGenerator apG;
for (int i = 0; i < validValues.length; i++) {
apG = AlgorithmParameterGenerator.getInstance(validValues[i], mProv);
assertEquals("Incorrect algorithm", apG.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", apG.getProvider(), mProv);
checkResult(apG);
}
}
use of java.security.AlgorithmParameterGenerator in project robovm by robovm.
the class AlgorithmParameterGenerator2Test method testGetInstance02.
/**
* Test for <code>getInstance(String algorithm, String provider)</code>
* method
* Assertions:
* throws NullPointerException must be thrown is null
* throws NoSuchAlgorithmException must be thrown if algorithm is not available
* throws IllegalArgumentException when provider is null;
* throws NoSuchProviderException when provider is available;
* returns AlgorithmParameterGenerator object
*/
public void testGetInstance02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException {
try {
AlgorithmParameterGenerator.getInstance(null, mProv.getName());
fail("NullPointerException or NoSuchAlgorithmException should be thrown");
} catch (NullPointerException e) {
} catch (NoSuchAlgorithmException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
AlgorithmParameterGenerator.getInstance(invalidValues[i], mProv.getName());
fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
String prov = null;
for (int i = 0; i < validValues.length; i++) {
try {
AlgorithmParameterGenerator.getInstance(validValues[i], prov);
fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (IllegalArgumentException e) {
}
}
for (int i = 0; i < validValues.length; i++) {
for (int j = 1; j < invalidValues.length; j++) {
try {
AlgorithmParameterGenerator.getInstance(validValues[i], invalidValues[j]);
fail("NoSuchProviderException must be thrown (algorithm: ".concat(invalidValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
} catch (NoSuchProviderException e) {
}
}
}
AlgorithmParameterGenerator apG;
for (int i = 0; i < validValues.length; i++) {
apG = AlgorithmParameterGenerator.getInstance(validValues[i], mProv.getName());
assertEquals("Incorrect algorithm", apG.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", apG.getProvider().getName(), mProv.getName());
checkResult(apG);
}
}
use of java.security.AlgorithmParameterGenerator in project robovm by robovm.
the class AlgorithmParameterGeneratorTest method testAlgorithmParameterGenerator.
public void testAlgorithmParameterGenerator() {
AlgorithmParameterGenerator generator = null;
try {
generator = AlgorithmParameterGenerator.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
fail(e.getMessage());
}
generator.init(1024);
AlgorithmParameters parameters = generator.generateParameters();
assertNotNull("generated parameters are null", parameters);
helper.test(parameters);
}
use of java.security.AlgorithmParameterGenerator in project robovm by robovm.
the class OldAlgorithmParameterGeneratorTest method test_initILjava_security_SecureRandom.
public void test_initILjava_security_SecureRandom() throws Exception {
// Test for method void
// java.security.AlgorithmParameterGenerator.init(int,
// java.security.SecureRandom)
// checks that no exception is thrown
int[] valid = { 512, 576, 640, 960, 1024 };
AlgorithmParameterGenerator gen = AlgorithmParameterGenerator.getInstance("DSA");
for (int i = 0; i < valid.length; i++) {
try {
gen.init(valid[i], new SecureRandom());
gen.init(valid[i], null);
} catch (Exception e) {
fail("Exception should not be thrown for valid parameter" + valid[i]);
}
}
}
use of java.security.AlgorithmParameterGenerator in project robovm by robovm.
the class OldDHTest method testDHGen.
@BrokenTest("Suffers from DH slowness, disabling for now")
public void testDHGen() throws Exception {
KeyPairGenerator gen = null;
try {
gen = KeyPairGenerator.getInstance("DH");
} catch (NoSuchAlgorithmException e) {
fail(e.getMessage());
}
AlgorithmParameterGenerator algorithmparametergenerator = AlgorithmParameterGenerator.getInstance("DH");
algorithmparametergenerator.init(1024, new SecureRandom());
AlgorithmParameters algorithmparameters = algorithmparametergenerator.generateParameters();
DHParameterSpec dhparameterspec = algorithmparameters.getParameterSpec(DHParameterSpec.class);
//gen.initialize(1024);
gen.initialize(dhparameterspec);
KeyPair key = gen.generateKeyPair();
}
Aggregations