001    package org.apache.fulcrum.jce.crypto;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.io.IOException;
023    import java.io.InputStream;
024    import java.io.OutputStream;
025    import java.security.GeneralSecurityException;
026    
027    /**
028     * Interface for creating encrypting/decrypting streams. 
029     *
030     * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
031     */
032    
033    public interface CryptoStreamFactory
034    {
035        /**
036         * Creates input stream based on the decryption mode
037         * using the default password.
038         *
039         * @param is the input stream to be wrapped
040         * @param decryptionMode the decryption mode (true|false|auto)
041         * @return an decrypting input stream
042         * @throws GeneralSecurityException creating the input stream failed
043         * @throws IOException creating the input stream failed
044         */
045        InputStream getInputStream(InputStream is, String decryptionMode)
046            throws GeneralSecurityException, IOException;
047    
048        /**
049         * Creates input stream based on the decryption mode
050         * using the given password.
051         *
052         * @param is the input stream to be wrapped
053         * @param decryptionMode the decryption mode (true|false|auto)
054         * @param password the password to be used
055         * @return an decrypting input stream
056         * @throws GeneralSecurityException creating the input stream failed
057         * @throws IOException creating the input stream failed
058         */
059        InputStream getInputStream(InputStream is, String decryptionMode, char[] password)
060            throws GeneralSecurityException, IOException;
061    
062        /**
063         * Creates a decrypting input stream using the default password.
064         *
065         * @param is the input stream to be wrapped
066         * @return an decrypting input stream
067         * @throws GeneralSecurityException creating the input stream failed
068         * @throws IOException creating the input stream failed
069         */
070        InputStream getInputStream(InputStream is)
071            throws GeneralSecurityException, IOException;
072    
073        /**
074         * Creates an decrypting input stream using a given password.
075         *
076         * @param is the input stream to be wrapped
077         * @param password the password to be used
078         * @return an decrypting input stream
079         * @throws GeneralSecurityException creating the input stream failed
080         * @throws IOException creating the input stream failed
081         */
082        InputStream getInputStream(InputStream is, char[] password)
083            throws GeneralSecurityException, IOException;
084    
085        /**
086         * Creates a smart decrypting input stream using the default
087         * password. The implementation looks at the binary content
088         * to decide if it was encrypted or not thereby providing
089         * transparent access to encrypted/unencrypted files.
090         *
091         * @param is the input stream to be wrapped
092         * @return an decrypting input stream
093         * @throws GeneralSecurityException creating the input stream failed
094         * @throws IOException creating the input stream failed
095         */
096        InputStream getSmartInputStream(InputStream is)
097            throws GeneralSecurityException, IOException;
098    
099        /**
100         * Creates a smart decrypting input stream using a given
101         * password. The implementation looks at the binary content
102         * to decide if it was encrypted or not thereby providing
103         * transparent access to encrypted/unencrypted files.
104         *
105         * @param is the input stream to be wrapped
106         * @param password the password to be used
107         * @return an decrypting input stream
108         * @throws GeneralSecurityException creating the input stream failed
109         * @throws IOException creating the input stream failed
110         */
111        InputStream getSmartInputStream(InputStream is, char[] password)
112            throws GeneralSecurityException, IOException;
113    
114        /**
115         * Creates an encrypting output stream using the default password.
116         *
117         * @param os the output stream to be wrapped
118         * @return an decrypting input stream
119         * @throws GeneralSecurityException creating the ouptut stream failed
120         * @throws IOException creating the ouptut stream failed
121         */
122        OutputStream getOutputStream(OutputStream os)
123            throws GeneralSecurityException, IOException;
124    
125        /**
126         * Creates an encrypting output stream using the given password.
127         *
128         * @param os the output stream to be wrapped
129         * @param password the password to be used
130         * @return an decrypting input stream
131         * @throws GeneralSecurityException creating the ouptut stream failed
132         * @throws IOException creating the ouptut stream failed
133         */
134        OutputStream getOutputStream(OutputStream os, char[] password)
135            throws GeneralSecurityException, IOException;
136    }