use of javax.crypto.NullCipher in project robovm by robovm.
the class FilterInputStreamNullSourceTest method testCipherInputStream.
public void testCipherInputStream() throws IOException {
InputStream in = new CipherInputStream(null, new NullCipher());
try {
in.read();
fail();
} catch (NullPointerException expected) {
}
assertEquals(0, in.available());
try {
in.close();
fail();
} catch (NullPointerException expected) {
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class SealedObjectTest method testReadObject.
/**
* readObject(ObjectInputStream s) method testing. Tests if the
* serialization/deserialization works correctly: object is serialized,
* deserialized, the content od deserialized object equals to the content of
* initial object.
*/
public void testReadObject() throws Exception {
String secret = "secret string";
SealedObject so = new SealedObject(secret, new NullCipher());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(so);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
SealedObject so_des = (SealedObject) ois.readObject();
assertEquals("The secret content of deserialized object " + "should be equal to the secret content of initial object", secret, so_des.getObject(new NullCipher()));
assertEquals("The value returned by getAlgorithm() method of " + "deserialized object should be equal to the value returned " + "by getAlgorithm() method of initial object", so.getAlgorithm(), so_des.getAlgorithm());
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class SealedObjectTest method testGetObject2.
/**
* getObject(Cipher c) method testing. Tests if the proper exception is
* thrown in the case of incorrect input parameters and if the object sealed
* with encryption algorithm and specified parameters can be retrieved by
* specifying the initialized Cipher object.
*/
public void testGetObject2() throws Exception {
try {
new SealedObject("secret string", new NullCipher()).getObject((Cipher) null);
fail("NullPointerException should be thrown in the case of " + "null cipher.");
} catch (NullPointerException e) {
}
KeyGenerator kg = KeyGenerator.getInstance("DES");
Key key = kg.generateKey();
IvParameterSpec ips = new IvParameterSpec(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 });
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, ips);
String secret = "secret string";
SealedObject so = new SealedObject(secret, cipher);
cipher.init(Cipher.DECRYPT_MODE, key, ips);
assertEquals("The returned object does not equals to the " + "original object.", secret, so.getObject(cipher));
try {
so.getObject((Cipher) null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
//expected
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class NullCipherTest method testDoFinalbyteArrayintintbyteArray2.
/*
* Class under test for int doFinal(byte[], int, int, byte[])
*/
public void testDoFinalbyteArrayintintbyteArray2() throws Exception {
//Regression for HARMONY-758
try {
new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE, new byte[1]);
fail("Expected IllegalArgumentException was not thrown");
} catch (IllegalArgumentException e) {
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class NullCipherTest method testUpdatebyteArrayintint2.
/*
* Class under test for byte[] update(byte[], int, int)
*/
public void testUpdatebyteArrayintint2() {
//Regression for HARMONY-758
try {
new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE);
fail("Expected IllegalArgumentException was not thrown");
} catch (IllegalArgumentException e) {
}
}
Aggregations