use of javax.crypto.KeyGenerator in project robovm by robovm.
the class ExemptionMechanismTest method test_initLjava_security_KeyLjava_security_spec_AlgorithmParameterSpec.
public void test_initLjava_security_KeyLjava_security_spec_AlgorithmParameterSpec() throws Exception {
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
};
Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
try {
em.init(key, (AlgorithmParameterSpec) null);
fail("InvalidAlgorithmParameterException expected");
} catch (InvalidAlgorithmParameterException e) {
//expected
}
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(56, new SecureRandom());
key = kg.generateKey();
try {
em.init(null, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
try {
em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
fail("ExemptionMechanismException expected");
} catch (ExemptionMechanismException e) {
//expected
}
}
use of javax.crypto.KeyGenerator in project robovm by robovm.
the class myKeyGenerator method testGetInstanceString02.
/*
* Test for <code> getInstance(String algorithm) </code> method
* Assertions: returns KeyGenerator object
*/
public void testGetInstanceString02() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGenerator keyG;
for (int i = 0; i < validValues.length; i++) {
keyG = KeyGenerator.getInstance(validValues[i]);
assertEquals("Incorrect algorithm", keyG.getAlgorithm(), validValues[i]);
}
}
use of javax.crypto.KeyGenerator in project robovm by robovm.
the class myKeyGenerator method testGetInstanceStringProvider03.
/*
* Test for <code> getInstance(String algorithm, Provider provider)</code> method
* Assertions: returns KeyGenerator object
*/
public void testGetInstanceStringProvider03() throws IllegalArgumentException, NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGenerator keyA;
for (int i = 0; i < validValues.length; i++) {
keyA = KeyGenerator.getInstance(validValues[i], defaultProvider);
assertEquals("Incorrect algorithm", keyA.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", keyA.getProvider(), defaultProvider);
}
}
use of javax.crypto.KeyGenerator in project robovm by robovm.
the class myKeyGenerator method testKeyGenerator.
/**
* Test for <code>KeyGenerator</code> constructor Assertion: returns
* KeyGenerator object
*/
public void testKeyGenerator() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGeneratorSpi spi = new MyKeyGeneratorSpi();
KeyGenerator keyG = new myKeyGenerator(spi, defaultProvider, defaultAlgorithm);
assertEquals("Incorrect algorithm", keyG.getAlgorithm(), defaultAlgorithm);
assertEquals("Incorrect provider", keyG.getProvider(), defaultProvider);
AlgorithmParameterSpec params = null;
int keysize = 0;
try {
keyG.init(params, null);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
try {
keyG.init(keysize, null);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
keyG = new myKeyGenerator(null, null, null);
assertNull("Algorithm must be null", keyG.getAlgorithm());
assertNull("Provider must be null", keyG.getProvider());
try {
keyG.init(params, null);
fail("NullPointerException must be thrown");
} catch (NullPointerException e) {
}
try {
keyG.init(keysize, null);
fail("NullPointerException or InvalidParameterException must be thrown");
} catch (InvalidParameterException e) {
} catch (NullPointerException e) {
}
}
use of javax.crypto.KeyGenerator in project robovm by robovm.
the class myKeyGenerator method testGetInstanceStringString03.
/*
* Test for <code> getInstance(String algorithm, String provider)</code> method
* Assertions: returns KeyGenerator object
*/
public void testGetInstanceStringString03() throws IllegalArgumentException, NoSuchAlgorithmException, NoSuchProviderException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGenerator keyG;
for (int i = 0; i < validValues.length; i++) {
keyG = KeyGenerator.getInstance(validValues[i], defaultProviderName);
assertEquals("Incorrect algorithm", keyG.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", keyG.getProvider().getName(), defaultProviderName);
}
}
Aggregations