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);
}
}
use of javax.crypto.KeyGenerator in project robovm by robovm.
the class myKeyGenerator method testInitParams.
/*
* Test for <code>init(AlgorithmParameterSpec params)</code> and
* <code>init(AlgorithmParameterSpec params, SecureRandom random)</code> methods
* Assertion: throws InvalidAlgorithmParameterException when params is null
*/
public void testInitParams() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGenerator[] kgs = createKGs();
AlgorithmParameterSpec aps = null;
for (int i = 0; i < kgs.length; i++) {
try {
kgs[i].init(aps);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
try {
kgs[i].init(aps, new SecureRandom());
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
}
}
use of javax.crypto.KeyGenerator in project robovm by robovm.
the class CipherOutputStream1Test method test_ConstructorLjava_io_OutputStreamLjavax_crypto_Cipher.
public void test_ConstructorLjava_io_OutputStreamLjavax_crypto_Cipher() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(56, new SecureRandom());
Key key = kg.generateKey();
Cipher c = Cipher.getInstance("DES/CBC/NoPadding");
c.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(baos, c);
assertNotNull(cos);
}
Aggregations