1 package org.apache.fulcrum.jce.crypto;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.security.GeneralSecurityException;
26
27 /**
28 * Interface for creating encrypting/decrypting streams.
29 *
30 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl </a>
31 */
32
33 public interface CryptoStreamFactory
34 {
35 /**
36 * Creates input stream based on the decryption mode
37 * using the default password.
38 *
39 * @param is the input stream to be wrapped
40 * @param decryptionMode the decryption mode (true|false|auto)
41 * @return an decrypting input stream
42 * @throws GeneralSecurityException creating the input stream failed
43 * @throws IOException creating the input stream failed
44 */
45 InputStream getInputStream(InputStream is, String decryptionMode)
46 throws GeneralSecurityException, IOException;
47
48 /**
49 * Creates input stream based on the decryption mode
50 * using the given password.
51 *
52 * @param is the input stream to be wrapped
53 * @param decryptionMode the decryption mode (true|false|auto)
54 * @param password the password to be used
55 * @return an decrypting input stream
56 * @throws GeneralSecurityException creating the input stream failed
57 * @throws IOException creating the input stream failed
58 */
59 InputStream getInputStream(InputStream is, String decryptionMode, char[] password)
60 throws GeneralSecurityException, IOException;
61
62 /**
63 * Creates a decrypting input stream using the default password.
64 *
65 * @param is the input stream to be wrapped
66 * @return an decrypting input stream
67 * @throws GeneralSecurityException creating the input stream failed
68 * @throws IOException creating the input stream failed
69 */
70 InputStream getInputStream(InputStream is)
71 throws GeneralSecurityException, IOException;
72
73 /**
74 * Creates an decrypting input stream using a given password.
75 *
76 * @param is the input stream to be wrapped
77 * @param password the password to be used
78 * @return an decrypting input stream
79 * @throws GeneralSecurityException creating the input stream failed
80 * @throws IOException creating the input stream failed
81 */
82 InputStream getInputStream(InputStream is, char[] password)
83 throws GeneralSecurityException, IOException;
84
85 /**
86 * Creates a smart decrypting input stream using the default
87 * password. The implementation looks at the binary content
88 * to decide if it was encrypted or not thereby providing
89 * transparent access to encrypted/unencrypted files.
90 *
91 * @param is the input stream to be wrapped
92 * @return an decrypting input stream
93 * @throws GeneralSecurityException creating the input stream failed
94 * @throws IOException creating the input stream failed
95 */
96 InputStream getSmartInputStream(InputStream is)
97 throws GeneralSecurityException, IOException;
98
99 /**
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 encrypting output stream
119 * @throws GeneralSecurityException creating the output stream failed
120 * @throws IOException creating the output 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 encrypting output stream
131 * @throws GeneralSecurityException creating the output stream failed
132 * @throws IOException creating the output stream failed
133 */
134 OutputStream getOutputStream(OutputStream os, char[] password)
135 throws GeneralSecurityException, IOException;
136
137 /**
138 * Info about used algorithm.
139 * @return algorithm string
140 */
141 String getAlgorithm();
142
143 }