use of java.security.spec.InvalidParameterSpecException in project robovm by robovm.
the class AlgorithmParametersTest method testAlgorithmParameters.
public void testAlgorithmParameters() {
AlgorithmParameters algorithmParameters = null;
try {
algorithmParameters = AlgorithmParameters.getInstance(algorithmName);
} catch (NoSuchAlgorithmException e) {
fail(e.getMessage());
}
try {
algorithmParameters.init(parameterData);
} catch (InvalidParameterSpecException e) {
fail(e.getMessage());
}
helper.test(algorithmParameters);
}
use of java.security.spec.InvalidParameterSpecException in project platform_frameworks_base by android.
the class AndroidKeyStoreUnauthenticatedAESCipherSpi method engineGetParameters.
@Nullable
@Override
protected final AlgorithmParameters engineGetParameters() {
if (!mIvRequired) {
return null;
}
if ((mIv != null) && (mIv.length > 0)) {
try {
AlgorithmParameters params = AlgorithmParameters.getInstance("AES");
params.init(new IvParameterSpec(mIv));
return params;
} catch (NoSuchAlgorithmException e) {
throw new ProviderException("Failed to obtain AES AlgorithmParameters", e);
} catch (InvalidParameterSpecException e) {
throw new ProviderException("Failed to initialize AES AlgorithmParameters with an IV", e);
}
}
return null;
}
use of java.security.spec.InvalidParameterSpecException in project j2objc by google.
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 j2objc by google.
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 OpenSSLCipher method engineInit.
@Override
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
final AlgorithmParameterSpec spec;
try {
spec = params.getParameterSpec(IvParameterSpec.class);
} catch (InvalidParameterSpecException e) {
throw new InvalidAlgorithmParameterException(e);
}
engineInit(opmode, key, spec, random);
}
Aggregations