Search in sources :

Example 16 with NullCipher

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) {
    }
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) NullCipher(javax.crypto.NullCipher) DataInputStream(java.io.DataInputStream) CheckedInputStream(java.util.zip.CheckedInputStream) BufferedInputStream(java.io.BufferedInputStream) PushbackInputStream(java.io.PushbackInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) CipherInputStream(javax.crypto.CipherInputStream) LineNumberInputStream(java.io.LineNumberInputStream) FilterInputStream(java.io.FilterInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream)

Example 17 with NullCipher

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());
}
Also used : NullCipher(javax.crypto.NullCipher) ByteArrayInputStream(java.io.ByteArrayInputStream) SealedObject(javax.crypto.SealedObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 18 with NullCipher

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
    }
}
Also used : NullCipher(javax.crypto.NullCipher) SealedObject(javax.crypto.SealedObject) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) NullCipher(javax.crypto.NullCipher) KeyGenerator(javax.crypto.KeyGenerator) Key(java.security.Key)

Example 19 with NullCipher

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) {
    }
}
Also used : NullCipher(javax.crypto.NullCipher)

Example 20 with NullCipher

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) {
    }
}
Also used : NullCipher(javax.crypto.NullCipher)

Aggregations

NullCipher (javax.crypto.NullCipher)25 CipherInputStream (javax.crypto.CipherInputStream)9 Cipher (javax.crypto.Cipher)6 SealedObject (javax.crypto.SealedObject)5 CipherOutputStream (javax.crypto.CipherOutputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Key (java.security.Key)2 KeyGenerator (javax.crypto.KeyGenerator)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FilterInputStream (java.io.FilterInputStream)1 InputStream (java.io.InputStream)1 LineNumberInputStream (java.io.LineNumberInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 PushbackInputStream (java.io.PushbackInputStream)1 DigestInputStream (java.security.DigestInputStream)1