use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class MyProvider method test_engineInit_02.
/**
* @throws InvalidAlgorithmParameterException
* @throws NoSuchAlgorithmException
* javax.net.ssl.TrustManagerFactorySpi#engineInit(ManagerFactoryParameters spec)
*/
public void test_engineInit_02() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
factory.reset();
Provider provider = new MyProvider();
TrustManagerFactory tmf = TrustManagerFactory.getInstance("MyTMF", provider);
Parameters pr = null;
try {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
pr = new Parameters(ks);
tmf.init(pr);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
assertTrue(factory.isEngineInitCalled());
assertEquals(pr, factory.getSpec());
factory.reset();
tmf.init((ManagerFactoryParameters) null);
assertTrue(factory.isEngineInitCalled());
assertNull(factory.getSpec());
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class TrustManagerFactory2Test method checkResult.
private void checkResult(TrustManagerFactory tmf) throws Exception {
KeyStore kStore = null;
ManagerFactoryParameters mfp = null;
try {
tmf.init(kStore);
fail("KeyStoreException must be thrown");
} catch (KeyStoreException e) {
}
try {
tmf.init(mfp);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
assertNull("getTrustManagers() should return null object", tmf.getTrustManagers());
try {
kStore = KeyStore.getInstance(KeyStore.getDefaultType());
kStore.load(null, null);
} catch (KeyStoreException e) {
fail("default keystore is not supported");
return;
}
tmf.init(kStore);
mfp = (ManagerFactoryParameters) new MyTrustManagerFactorySpi.Parameters(null);
try {
tmf.init(mfp);
fail("RuntimeException must be thrown");
} catch (RuntimeException e) {
assertTrue("Incorrect exception", e.getCause() instanceof KeyStoreException);
}
mfp = (ManagerFactoryParameters) new MyTrustManagerFactorySpi.Parameters(kStore);
tmf.init(mfp);
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class myAlgPG method testAlgorithmParameterGenerator12.
/**
* Test for <code>init(AlgorithmParameterSpec param)</code> and
* <code>init(AlgorithmParameterSpec param, SecureRandom random<code>
* methods
* Assertion: throws InvalidAlgorithmParameterException when param is null
*/
public void testAlgorithmParameterGenerator12() {
if (!DSASupported) {
fail(validAlgName + " algorithm is not supported");
return;
}
SecureRandom random = new SecureRandom();
AlgorithmParameterSpec aps = null;
AlgorithmParameterGenerator[] apgs = createAPGen();
assertNotNull("AlgorithmParameterGenerator objects were not created", apgs);
for (int i = 0; i < apgs.length; i++) {
try {
apgs[i].init(aps);
fail("InvalidAlgorithmParameterException expected for null argument.");
} catch (InvalidAlgorithmParameterException e) {
//expected
}
try {
apgs[i].init(aps, random);
fail("InvalidAlgorithmParameterException expected for null argument.");
} catch (InvalidAlgorithmParameterException e) {
//expected
}
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class AlgorithmParameterSignatureHelper method test.
@Override
public void test(AlgorithmParameters parameters) {
Signature signature = null;
try {
signature = Signature.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
Assert.fail(e.getMessage());
}
T parameterSpec = null;
try {
parameterSpec = parameters.getParameterSpec(parameterSpecClass);
} catch (InvalidParameterSpecException e) {
Assert.fail(e.getMessage());
}
KeyPairGenerator generator = null;
try {
generator = KeyPairGenerator.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
Assert.fail(e.getMessage());
}
try {
generator.initialize(parameterSpec);
} catch (InvalidAlgorithmParameterException e) {
Assert.fail(e.getMessage());
}
KeyPair keyPair = generator.genKeyPair();
try {
signature.initSign(keyPair.getPrivate());
} catch (InvalidKeyException e) {
Assert.fail(e.getMessage());
}
try {
signature.update(plainData.getBytes());
} catch (SignatureException e) {
Assert.fail(e.getMessage());
}
byte[] signed = null;
try {
signed = signature.sign();
} catch (SignatureException e) {
Assert.fail(e.getMessage());
}
try {
signature.initVerify(keyPair.getPublic());
} catch (InvalidKeyException e) {
Assert.fail(e.getMessage());
}
try {
signature.update(plainData.getBytes());
} catch (SignatureException e) {
Assert.fail(e.getMessage());
}
try {
Assert.assertTrue("signature could not be verified", signature.verify(signed));
} catch (SignatureException e) {
Assert.fail(e.getMessage());
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class AlgorithmParameterSymmetricHelper method test.
@Override
public void test(AlgorithmParameters parameters) {
KeyGenerator generator = null;
try {
generator = KeyGenerator.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
Assert.fail(e.getMessage());
}
generator.init(keySize);
Key key = generator.generateKey();
Cipher cipher = null;
try {
String transformation = algorithmName;
if (blockmode != null) {
transformation += "/" + blockmode;
}
cipher = Cipher.getInstance(transformation);
} catch (NoSuchAlgorithmException e) {
Assert.fail(e.getMessage());
} catch (NoSuchPaddingException e) {
Assert.fail(e.getMessage());
}
try {
cipher.init(Cipher.ENCRYPT_MODE, key, parameters);
} catch (InvalidKeyException e) {
Assert.fail(e.getMessage());
} catch (InvalidAlgorithmParameterException e) {
Assert.fail(e.getMessage());
}
byte[] bs = null;
try {
bs = cipher.doFinal(plainData.getBytes());
} catch (IllegalBlockSizeException e) {
Assert.fail(e.getMessage());
} catch (BadPaddingException e) {
Assert.fail(e.getMessage());
}
try {
cipher.init(Cipher.DECRYPT_MODE, key, parameters);
} catch (InvalidKeyException e) {
Assert.fail(e.getMessage());
} catch (InvalidAlgorithmParameterException e) {
Assert.fail(e.getMessage());
}
byte[] decrypted = null;
try {
decrypted = cipher.doFinal(bs);
} catch (IllegalBlockSizeException e) {
Assert.fail(e.getMessage());
} catch (BadPaddingException e) {
Assert.fail(e.getMessage());
}
Assert.assertTrue(Arrays.equals(plainData.getBytes(), decrypted));
}
Aggregations