use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class CipherTest method test_initWithKeyAlgorithmParameters.
public void test_initWithKeyAlgorithmParameters() throws Exception {
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, ap);
assertNotNull(c.getParameters());
try {
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_3DES, ap);
fail();
} catch (InvalidKeyException expected) {
}
try {
c.init(Cipher.DECRYPT_MODE, CIPHER_KEY_DES, (AlgorithmParameters) null);
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class CipherTest method test_initWithAlgorithmParameterSpec.
/**
* javax.crypto.Cipher#init(int, java.security.Key,
* java.security.spec.AlgorithmParameterSpec)
*/
public void test_initWithAlgorithmParameterSpec() throws Exception {
AlgorithmParameterSpec ap = new IvParameterSpec(IV);
Cipher cipher = Cipher.getInstance(ALGORITHM_3DES + "/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, CIPHER_KEY_3DES, ap);
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);
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);
fail();
} catch (InvalidAlgorithmParameterException expected) {
}
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class AlgorithmParameterGeneratorSpiTest method testAlgorithmParameterGeneratorSpi01.
/**
* Test for <code>AlgorithmParameterGeneratorSpi</code> constructor
* Assertion: constructs AlgorithmParameterGeneratorSpi
*/
public void testAlgorithmParameterGeneratorSpi01() throws InvalidAlgorithmParameterException {
MyAlgorithmParameterGeneratorSpi algParGen = new MyAlgorithmParameterGeneratorSpi();
AlgorithmParameters param = algParGen.engineGenerateParameters();
assertNull("Not null parameters", param);
AlgorithmParameterSpec pp = null;
algParGen.engineInit(pp, new SecureRandom());
try {
algParGen.engineInit(pp, null);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
algParGen.engineInit(0, null);
algParGen.engineInit(0, new SecureRandom());
try {
algParGen.engineInit(-10, null);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
try {
algParGen.engineInit(-10, new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class OAEPParameterSpecTest method testOAEPParameterSpec.
/**
* OAEPParameterSpec(String mdName, String mgfName, AlgorithmParameterSpec
* mgfSpec, PSource pSrc) method testing. Tests that NullPointerException
* is thrown in the case of inappropriate constructor parameters and checks
* the value of DEFAULT field.
*/
public void testOAEPParameterSpec() {
// using init values for OAEPParameterSpec.DEFAULT
String mdName = "SHA-1";
String mgfName = "MGF1";
AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
PSource pSrc = PSource.PSpecified.DEFAULT;
try {
new OAEPParameterSpec(null, mgfName, mgfSpec, pSrc);
fail("NullPointerException should be thrown in the case of " + "null mdName.");
} catch (NullPointerException e) {
}
try {
new OAEPParameterSpec(mdName, null, mgfSpec, pSrc);
fail("NullPointerException should be thrown in the case of " + "null mgfName.");
} catch (NullPointerException e) {
}
try {
new OAEPParameterSpec(mdName, mgfName, mgfSpec, null);
fail("NullPointerException should be thrown in the case of " + "null pSrc.");
} catch (NullPointerException e) {
}
assertTrue("The message digest algorithm name of " + "OAEPParameterSpec.DEFAULT field should be " + mdName, OAEPParameterSpec.DEFAULT.getDigestAlgorithm().equals(mdName));
assertTrue("The mask generation function algorithm name of " + "OAEPParameterSpec.DEFAULT field should be " + mgfName, OAEPParameterSpec.DEFAULT.getMGFAlgorithm().equals(mgfName));
assertTrue("The mask generation function parameters of " + "OAEPParameterSpec.DEFAULT field should be the same object " + "as MGF1ParameterSpec.SHA1", OAEPParameterSpec.DEFAULT.getMGFParameters() == MGF1ParameterSpec.SHA1);
assertTrue("The source of the encoding input P of " + "OAEPParameterSpec.DEFAULT field should be the same object " + "PSource.PSpecified.DEFAULT", OAEPParameterSpec.DEFAULT.getPSource() == PSource.PSpecified.DEFAULT);
}
use of java.security.spec.AlgorithmParameterSpec in project robovm by robovm.
the class OAEPParameterSpecTest method testGetMGFAlgorithm.
/**
* getMGFAlgorithm() method testing.
*/
public void testGetMGFAlgorithm() {
String mdName = "SHA-1";
String mgfName = "MGF1";
AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
PSource pSrc = PSource.PSpecified.DEFAULT;
OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName, mgfSpec, pSrc);
assertTrue("The returned value does not equal to the " + "value specified in the constructor.", ps.getMGFAlgorithm().equals(mgfName));
}
Aggregations