use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class BaseWrapCipher method engineInit.
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
AlgorithmParameterSpec paramSpec = null;
if (params != null) {
for (int i = 0; i != availableSpecs.length; i++) {
try {
paramSpec = params.getParameterSpec(availableSpecs[i]);
break;
} catch (Exception e) {
// try next spec
}
}
if (paramSpec == null) {
throw new InvalidAlgorithmParameterException("can't handle parameter " + params.toString());
}
}
engineParams = params;
engineInit(opmode, key, paramSpec, random);
}
use of java.security.spec.AlgorithmParameterSpec 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);
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class KeyPairGeneratorTest method test_getInstance.
public void test_getInstance() throws Exception {
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
Set<Provider.Service> services = provider.getServices();
for (Provider.Service service : services) {
String type = service.getType();
if (!type.equals("KeyPairGenerator")) {
continue;
}
String algorithm = service.getAlgorithm();
// AndroidKeyStore is tested in CTS.
if ("AndroidKeyStore".equals(provider.getName())) {
continue;
}
AlgorithmParameterSpec params = null;
// TODO: detect if we're running in vogar and run the full test
if ("DH".equals(algorithm)) {
params = getDHParams();
}
try {
// KeyPairGenerator.getInstance(String)
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(algorithm);
assertEquals(algorithm, kpg1.getAlgorithm());
if (params != null) {
kpg1.initialize(params);
}
test_KeyPairGenerator(kpg1);
// KeyPairGenerator.getInstance(String, Provider)
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(algorithm, provider);
assertEquals(algorithm, kpg2.getAlgorithm());
assertEquals(provider, kpg2.getProvider());
if (params != null) {
kpg2.initialize(params);
}
test_KeyPairGenerator(kpg2);
// KeyPairGenerator.getInstance(String, String)
KeyPairGenerator kpg3 = KeyPairGenerator.getInstance(algorithm, provider.getName());
assertEquals(algorithm, kpg3.getAlgorithm());
assertEquals(provider, kpg3.getProvider());
if (params != null) {
kpg3.initialize(params);
}
test_KeyPairGenerator(kpg3);
} catch (Exception e) {
throw new Exception("Problem testing KeyPairGenerator." + algorithm, e);
}
}
}
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class ExemptionMechanismSpiTest method testExemptionMechanismSpi01.
/**
* Test for <code>ExemptionMechanismSpi</code> constructor Assertion:
* constructs ExemptionMechanismSpi
* @throws Exception
*/
public void testExemptionMechanismSpi01() throws Exception {
Mock_ExemptionMechanismSpi emSpi = new Mock_ExemptionMechanismSpi() {
};
int len = MyExemptionMechanismSpi.getLength();
byte[] bbRes = emSpi.engineGenExemptionBlob();
assertEquals("Incorrect length", bbRes.length, len);
assertEquals("Incorrect result", emSpi.engineGenExemptionBlob(new byte[1], len), len);
assertEquals("Incorrect output size", 10, emSpi.engineGetOutputSize(100));
Key key = null;
AlgorithmParameters params = null;
AlgorithmParameterSpec parSpec = null;
try {
emSpi.engineInit(key);
fail("InvalidKeyException must be thrown");
} catch (InvalidKeyException e) {
}
try {
emSpi.engineInit(key, params);
fail("InvalidKeyException must be thrown");
} catch (InvalidKeyException e) {
}
try {
emSpi.engineInit(key, parSpec);
fail("InvalidKeyException must be thrown");
} catch (InvalidKeyException e) {
}
key = ((MyExemptionMechanismSpi) emSpi).new tmp1Key("Proba", new byte[0]);
try {
emSpi.engineInit(key);
fail("ExemptionMechanismException must be thrown");
} catch (ExemptionMechanismException e) {
}
try {
emSpi.engineInit(key, params);
fail("ExemptionMechanismException must be thrown");
} catch (ExemptionMechanismException e) {
}
try {
emSpi.engineInit(key, parSpec);
fail("ExemptionMechanismException must be thrown");
} catch (ExemptionMechanismException e) {
}
key = ((MyExemptionMechanismSpi) emSpi).new tmpKey("Proba", new byte[0]);
emSpi.engineInit(key);
emSpi.engineInit(key, AlgorithmParameters.getInstance("DH"));
emSpi.engineInit(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
assertEquals("Incorrect result", 10, emSpi.engineGetOutputSize(100));
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class KeyAgreementSpiTest method testKeyAgreementSpi01.
/**
* Test for <code>KeyAgreementSpi</code> constructor Assertion: constructs
* KeyAgreementSpi
*/
public void testKeyAgreementSpi01() throws InvalidKeyException, ShortBufferException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
Mock_KeyAgreementSpi kaSpi = new Mock_KeyAgreementSpi();
assertNull("Not null result", kaSpi.engineDoPhase(null, true));
try {
kaSpi.engineDoPhase(null, false);
fail("IllegalStateException must be thrown");
} catch (IllegalStateException e) {
}
byte[] bb = kaSpi.engineGenerateSecret();
assertEquals("Length is not 0", bb.length, 0);
assertEquals("Returned integer is not 0", kaSpi.engineGenerateSecret(new byte[1], 10), -1);
assertNull("Not null result", kaSpi.engineGenerateSecret("aaa"));
try {
kaSpi.engineGenerateSecret("");
fail("NoSuchAlgorithmException must be thrown");
} catch (NoSuchAlgorithmException e) {
}
Key key = null;
try {
kaSpi.engineInit(key, new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
AlgorithmParameterSpec params = null;
try {
kaSpi.engineInit(key, params, new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
}
Aggregations