use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class OpenSSLECKeyPairGenerator method initialize.
@Override
public void initialize(AlgorithmParameterSpec param, SecureRandom random) throws InvalidAlgorithmParameterException {
if (param instanceof ECParameterSpec) {
ECParameterSpec ecParam = (ECParameterSpec) param;
group = OpenSSLECGroupContext.getInstance(ecParam);
} else if (param instanceof ECGenParameterSpec) {
ECGenParameterSpec ecParam = (ECGenParameterSpec) param;
final String curveName = ecParam.getName();
/*
* Store the group in a temporary variable until we know this is a
* valid group.
*/
final OpenSSLECGroupContext possibleGroup = OpenSSLECGroupContext.getCurveByName(curveName);
if (possibleGroup == null) {
throw new InvalidAlgorithmParameterException("unknown curve name: " + curveName);
}
group = possibleGroup;
} else {
throw new InvalidAlgorithmParameterException("parameter must be ECParameterSpec or ECGenParameterSpec");
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class OpenSSLRSAKeyPairGenerator method initialize.
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
if (!(params instanceof RSAKeyGenParameterSpec)) {
throw new InvalidAlgorithmParameterException("Only RSAKeyGenParameterSpec supported");
}
RSAKeyGenParameterSpec spec = (RSAKeyGenParameterSpec) params;
final BigInteger publicExponent = spec.getPublicExponent();
if (publicExponent != null) {
this.publicExponent = publicExponent.toByteArray();
}
this.modulusBits = spec.getKeysize();
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class ExemptionMechanismTest method test_initLjava_security_KeyLjava_security_AlgorithmParameters.
public void test_initLjava_security_KeyLjava_security_AlgorithmParameters() throws Exception {
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
};
Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
em.init(key, AlgorithmParameters.getInstance("DES"));
try {
em.init(key, (AlgorithmParameters) null);
fail("InvalidAlgorithmParameterException expected");
} catch (InvalidAlgorithmParameterException e) {
//expected
}
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(56, new SecureRandom());
key = kg.generateKey();
try {
em.init(null, AlgorithmParameters.getInstance("DES"));
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
try {
em.init(key, AlgorithmParameters.getInstance("DES"));
fail("ExemptionMechanismException expected");
} catch (ExemptionMechanismException e) {
//expected
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class ExemptionMechanismTest method test_initLjava_security_KeyLjava_security_spec_AlgorithmParameterSpec.
public void test_initLjava_security_KeyLjava_security_spec_AlgorithmParameterSpec() throws Exception {
Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
};
Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
try {
em.init(key, (AlgorithmParameterSpec) null);
fail("InvalidAlgorithmParameterException expected");
} catch (InvalidAlgorithmParameterException e) {
//expected
}
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(56, new SecureRandom());
key = kg.generateKey();
try {
em.init(null, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
try {
em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
fail("ExemptionMechanismException expected");
} catch (ExemptionMechanismException e) {
//expected
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class CipherTest method test_initWithKeyAlgorithmParameterSpecSecureRandom.
/**
* javax.crypto.Cipher#init(int, java.security.Key,
* java.security.spec.AlgorithmParameterSpec,
* java.security.SecureRandom)
*/
public void test_initWithKeyAlgorithmParameterSpecSecureRandom() throws Exception {
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher cipher = Cipher.getInstance(ALGORITHM_3DES + "/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, ap, new SecureRandom());
byte[] cipherIV = cipher.getIV();
assertTrue("IVs differ", Arrays.equals(cipherIV, IV));
cipher = Cipher.getInstance("DES/CBC/NoPadding");
try {
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, ap, new SecureRandom());
fail();
} catch (InvalidKeyException expected) {
}
cipher = Cipher.getInstance("DES/CBC/NoPadding");
ap = new RSAKeyGenParameterSpec(10, new BigInteger("10"));
try {
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_DES, ap, new SecureRandom());
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
Aggregations