use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.
the class CipherSpi method engineInit.
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
AlgorithmParameterSpec paramSpec = null;
if (params != null) {
try {
paramSpec = params.getParameterSpec(OAEPParameterSpec.class);
} catch (InvalidParameterSpecException e) {
throw new InvalidAlgorithmParameterException("cannot recognise parameters: " + e.toString(), e);
}
}
engineParams = params;
engineInit(opmode, key, paramSpec, random);
}
use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.
the class InvalidParameterSpecExceptionTest method testInvalidParameterSpecException01.
/**
* Test for <code>InvalidParameterSpecException()</code> constructor
* Assertion: constructs InvalidParameterSpecException with no detail
* message
*/
public void testInvalidParameterSpecException01() {
InvalidParameterSpecException tE = new InvalidParameterSpecException();
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.
the class AlgorithmParametersTest method test_getParameterSpecLjava_lang_Class.
/**
* java.security.AlgorithmParameters#getParameterSpec(Class)
*/
public void test_getParameterSpecLjava_lang_Class() throws Exception {
final MyAlgorithmParameterSpec myParamSpec = new MyAlgorithmParameterSpec();
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) {
return myParamSpec;
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
//
try {
params.getParameterSpec(null);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
try {
params.getParameterSpec(MyAlgorithmParameterSpec.class);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
//
// test: corresponding spi method is invoked
//
params.init(new MyAlgorithmParameterSpec());
assertSame(myParamSpec, params.getParameterSpec(MyAlgorithmParameterSpec.class));
//
// test: if paramSpec is null
// Regression test for HARMONY-2733
//
paramSpi = new MyAlgorithmParameters() {
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) {
// null is passed to spi-provider
assertNull(paramSpec);
return null;
}
};
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new MyAlgorithmParameterSpec());
assertNull(params.getParameterSpec(null));
}
use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.
the class AlgorithmParametersTest method test_initLjava_security_spec_AlgorithmParameterSpec.
/**
* java.security.AlgorithmParameters#init(java.security.spec.AlgorithmParameterSpec)
*/
public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception {
//
// test: corresponding spi method is invoked
//
final MyAlgorithmParameterSpec spec = new MyAlgorithmParameterSpec();
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
assertSame(spec, paramSpec);
runEngineInit_AlgParamSpec = true;
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(spec);
assertTrue(paramSpi.runEngineInit_AlgParamSpec);
//
try {
params.init(spec);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new byte[0]);
try {
params.init(spec);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new byte[0], "format");
try {
params.init(spec);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
//
// test: if paramSpec is null
//
paramSpi = new MyAlgorithmParameters() {
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
// null is passed to spi-provider
assertNull(paramSpec);
runEngineInit_AlgParamSpec = true;
}
};
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init((AlgorithmParameterSpec) null);
assertTrue(paramSpi.runEngineInit_AlgParamSpec);
}
use of java.security.spec.InvalidParameterSpecException 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());
}
}
Aggregations