use of java.security.KeyPairGenerator in project robovm by robovm.
the class KeyPairGenerator2Test method GetInstance03.
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code>
* method
* Assertions:
* throws NullPointerException when algorithm is null
* throws NoSuchAlgorithmException when algorithm is incorrect;
* throws IllegalArgumentException when provider is null;
* returns KeyPairGenerator object
*/
private void GetInstance03(int mode) throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException {
try {
KeyPairGenerator.getInstance(null, mProv);
fail("NullPointerException or KeyStoreException must be thrown");
} catch (NoSuchAlgorithmException e) {
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
KeyPairGenerator.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++) {
String alg = validValues[i].concat(post);
try {
KeyPairGenerator.getInstance(alg, prov);
fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(alg).concat(")"));
} catch (IllegalArgumentException e) {
}
}
KeyPairGenerator kpG;
for (int i = 0; i < validValues.length; i++) {
String alg = validValues[i].concat(post);
kpG = KeyPairGenerator.getInstance(alg, mProv);
assertEquals("Incorrect algorithm", kpG.getAlgorithm().toUpperCase(), (mode <= 2 ? resAlg : alg).toUpperCase());
assertEquals("Incorrect provider", kpG.getProvider(), mProv);
checkResult(kpG, mode);
}
}
use of java.security.KeyPairGenerator in project robovm by robovm.
the class KeyPairGenerator3Test method testGenKeyPair02.
/**
* Test for <code>generateKeyPair()</code> and <code>genKeyPair()</code>
* methods
* Assertion: these methods are used without previously initialization
*/
public void testGenKeyPair02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException {
if (!DSASupported) {
fail(NotSupportMsg);
return;
}
KeyPairGenerator[] kpg = createKPGen();
assertNotNull("KeyPairGenerator objects were not created", kpg);
KeyPair kp, kp1;
for (int i = 0; i < kpg.length; i++) {
kp = kpg[i].generateKeyPair();
kp1 = kpg[i].genKeyPair();
assertFalse("Incorrect private key", kp.getPrivate().equals(kp1.getPrivate()));
assertFalse("Incorrect public key", kp.getPublic().equals(kp1.getPublic()));
}
}
use of java.security.KeyPairGenerator in project robovm by robovm.
the class KeyPairGenerator3Test method testGenKeyPair01.
/**
* Test for <code>generateKeyPair()</code> and <code>genKeyPair()</code>
* methods
* Assertion: KeyPairGenerator was initialized before the invocation
* of these methods
*/
public void testGenKeyPair01() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException {
if (!DSASupported) {
fail(NotSupportMsg);
return;
}
KeyPairGenerator[] kpg = createKPGen();
assertNotNull("KeyPairGenerator objects were not created", kpg);
KeyPair kp, kp1;
SecureRandom rr = new SecureRandom();
for (int i = 0; i < kpg.length; i++) {
kpg[i].initialize(512, rr);
kp = kpg[i].generateKeyPair();
kp1 = kpg[i].genKeyPair();
assertFalse("Incorrect private key", kp.getPrivate().equals(kp1.getPrivate()));
assertFalse("Incorrect public key", kp.getPublic().equals(kp1.getPublic()));
}
}
use of java.security.KeyPairGenerator in project robovm by robovm.
the class KeyPairGenerator4Test method test_initializeLjava_security_spec_AlgorithmParameterSpec.
/**
* java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec)
*/
public void test_initializeLjava_security_spec_AlgorithmParameterSpec() throws Exception {
// create DSAParams
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
keyPairGenerator.initialize(1024);
DSAPublicKey key = (DSAPublicKey) keyPairGenerator.genKeyPair().getPublic();
DSAParams params = key.getParams();
KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
keyPair.initialize(new DSAParameterSpec(params.getP(), params.getQ(), params.getG()));
}
use of java.security.KeyPairGenerator in project robovm by robovm.
the class KeyPairGenerator4Test method test_initializeILjava_security_SecureRandom.
/**
* java.security.KeyPairGenerator#initialize(int,
* java.security.SecureRandom)
*/
public void test_initializeILjava_security_SecureRandom() throws Exception {
KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
keyPair.initialize(1024, new SecureRandom());
}
Aggregations