Java Code Examples for javax.crypto.CipherOutputStream

Following code examples demonstrate how to use javax.crypto.CipherOutputStreamfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use javax.crypto.CipherOutputStreamand various code implementation of this class.

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to CipherOutputStream.class!",
                   CipherOutputStream.class.isAssignableFrom(sut));
    } 


    public void test_close() throws Exception {
        try {
            new CipherOutputStream((OutputStream) null, Cipher
                    .getInstance("DES/CBC/PKCS5Padding")).close();
            fail("IllegalStateException expected");
        } catch (IllegalStateException e) {
        }

        CipherOutputStream ch = new CipherOutputStream((OutputStream) null) {};
        try {
            new CipherOutputStream(ch, Cipher
                    .getInstance("DES/CBC/PKCS5Padding")).close();
            fail("IllegalStateException expected");
        } catch (IllegalStateException e) {
        }
    } 

Advertisement
Javadoc
A CipherOutputStream is composed of an OutputStream and a Cipher so that write() methods first proce

ss the data before writing them out to the underlying OutputStream. The cipher must be fully initialized before being used by a CipherOutputStream.

For example, if the cipher is initialized for encryption, the CipherOutputStream will attempt to encrypt data before writing out the encrypted data.

This class adheres strictly to the semantics, especially the failure semantics, of its ancestor classes java.io.OutputStream and java.io.FilterOutputStream. This class has exactly those methods specified in its ancestor classes, and overrides them all. Moreover, this class catches all exceptions that are not thrown by its ancestor classes.

It is crucial for a programmer using this class not to use methods that are not defined or overriden in this class (such as a new method or constructor that is later added to one of the super classes), because the design and implementation of those methods are unlikely to have considered security impact with regard to CipherOutputStream. @author Li Gong @see java.io.OutputStream @see java.io.FilterOutputStream @see javax.crypto.Cipher @see javax.crypto.CipherInputStream @since 1.4

Read More
Advertisement