use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class KeyAgreementTest method testInit04.
/**
* Test for the methods:
* <code>init(Key key, AlgorithmParameterSpec params)</code>
* <code>init(Key key, AlgorithmParameterSpec params, SecureRandom random)</code>
* <code>generateSecret()</code>
* Assertions: initializes KeyAgreement and returns byte array
*/
public void testInit04() throws Exception, InvalidAlgorithmParameterException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
createKeys();
KeyAgreement[] kAgs = createKAs();
DHParameterSpec dhPs = ((DHPrivateKey) privKey).getParams();
AlgorithmParameterSpec aps = new RSAKeyGenParameterSpec(10, new BigInteger("10"));
byte[] bbRes1;
byte[] bbRes2;
byte[] bbRes3;
SecureRandom randomNull = null;
SecureRandom random = new SecureRandom();
for (int i = 0; i < kAgs.length; i++) {
kAgs[i].init(privKey, dhPs);
kAgs[i].doPhase(publKey, true);
bbRes1 = kAgs[i].generateSecret();
kAgs[i].init(privKey, dhPs, random);
kAgs[i].doPhase(publKey, true);
bbRes2 = kAgs[i].generateSecret();
assertEquals("Incorrect byte array length", bbRes1.length, bbRes2.length);
for (int j = 0; j < bbRes1.length; j++) {
assertEquals("Incorrect byte (index: ".concat(Integer.toString(i)).concat(")"), bbRes1[j], bbRes2[j]);
}
kAgs[i].init(privKey, dhPs, randomNull);
kAgs[i].doPhase(publKey, true);
bbRes3 = kAgs[i].generateSecret();
assertEquals("Incorrect byte array length", bbRes1.length, bbRes3.length);
for (int j = 0; j < bbRes1.length; j++) {
assertEquals("Incorrect byte (index: ".concat(Integer.toString(i)).concat(")"), bbRes1[j], bbRes3[j]);
}
try {
kAgs[i].init(publKey, dhPs, random);
fail("InvalidKeyException expected");
} catch (InvalidKeyException e) {
//expected
}
try {
kAgs[i].init(privKey, aps, random);
fail("InvalidAlgorithmParameterException expected");
} catch (InvalidAlgorithmParameterException e) {
//expected
}
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class APSpecSpi method testKeyGeneratorSpi01.
/**
* Test for <code>KeyGeneratorSpi</code> constructor Assertion: constructs
* KeyGeneratorSpi
*/
public void testKeyGeneratorSpi01() throws InvalidAlgorithmParameterException {
Mock_KeyGeneratorSpi kgSpi = new Mock_KeyGeneratorSpi();
assertNull("Not null result", kgSpi.engineGenerateKey());
try {
kgSpi.engineInit(77, new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
try {
kgSpi.engineInit(new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
AlgorithmParameterSpec aps = null;
try {
kgSpi.engineInit(aps, new SecureRandom());
fail("InvalidAlgorithmParameterException must be thrown when parameter is null");
} catch (InvalidAlgorithmParameterException e) {
}
aps = new APSpecSpi();
kgSpi.engineInit(aps, new SecureRandom());
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class myKeyGenerator method testKeyGenerator.
/**
* Test for <code>KeyGenerator</code> constructor Assertion: returns
* KeyGenerator object
*/
public void testKeyGenerator() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGeneratorSpi spi = new MyKeyGeneratorSpi();
KeyGenerator keyG = new myKeyGenerator(spi, defaultProvider, defaultAlgorithm);
assertEquals("Incorrect algorithm", keyG.getAlgorithm(), defaultAlgorithm);
assertEquals("Incorrect provider", keyG.getProvider(), defaultProvider);
AlgorithmParameterSpec params = null;
int keysize = 0;
try {
keyG.init(params, null);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
try {
keyG.init(keysize, null);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
keyG = new myKeyGenerator(null, null, null);
assertNull("Algorithm must be null", keyG.getAlgorithm());
assertNull("Provider must be null", keyG.getProvider());
try {
keyG.init(params, null);
fail("NullPointerException must be thrown");
} catch (NullPointerException e) {
}
try {
keyG.init(keysize, null);
fail("NullPointerException or InvalidParameterException must be thrown");
} catch (InvalidParameterException e) {
} catch (NullPointerException e) {
}
}
use of java.security.InvalidAlgorithmParameterException in project robovm by robovm.
the class myKeyGenerator method testInitParams.
/*
* Test for <code>init(AlgorithmParameterSpec params)</code> and
* <code>init(AlgorithmParameterSpec params, SecureRandom random)</code> methods
* Assertion: throws InvalidAlgorithmParameterException when params is null
*/
public void testInitParams() throws Exception {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
KeyGenerator[] kgs = createKGs();
AlgorithmParameterSpec aps = null;
for (int i = 0; i < kgs.length; i++) {
try {
kgs[i].init(aps);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
try {
kgs[i].init(aps, new SecureRandom());
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
}
}
use of java.security.InvalidAlgorithmParameterException in project aion by aionnetwork.
the class ECKeyPairGenerator method getInstance.
public static KeyPairGenerator getInstance(final Provider provider, final SecureRandom random) {
try {
final KeyPairGenerator gen = KeyPairGenerator.getInstance(ALGORITHM, provider);
gen.initialize(SECP256K1_CURVE, random);
return gen;
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(algorithmAssertionMsg, ex);
} catch (InvalidAlgorithmParameterException ex) {
throw new AssertionError(keySpecAssertionMsg, ex);
}
}
Aggregations