Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
Cipher | 34 | 0 | - | 0 | 0 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.crypto.cipher; | |
21 | ||
22 | import java.io.FilterInputStream; | |
23 | import java.io.FilterOutputStream; | |
24 | import java.io.InputStream; | |
25 | import java.io.OutputStream; | |
26 | import java.security.GeneralSecurityException; | |
27 | ||
28 | /** | |
29 | * Interface on a Block cipher engines ready to process data for encryption and decryption. | |
30 | * | |
31 | * @version $Id: 84ec9ab2bd6f01c857350a7ca4864deeb6c8d09a $ | |
32 | * @since 5.4M1 | |
33 | */ | |
34 | public interface Cipher | |
35 | { | |
36 | /** | |
37 | * @return the algorithm name of the underlying cipher. The returned string has in the form algorithm/mode/padding, | |
38 | * like in "DES/CBC/PKCS5Padding". | |
39 | */ | |
40 | String getAlgorithmName(); | |
41 | ||
42 | /** | |
43 | * @return the size of input data process as a block by this cipher (in bytes). | |
44 | */ | |
45 | int getInputBlockSize(); | |
46 | ||
47 | /** | |
48 | * @return the size of encrypted data returned for a block of input data (in bytes). | |
49 | */ | |
50 | int getOutputBlockSize(); | |
51 | ||
52 | /** | |
53 | * @return true if the cipher is initialised for encryption, and false for decryption. | |
54 | */ | |
55 | boolean isForEncryption(); | |
56 | ||
57 | /** | |
58 | * Return a filtered input stream based on this cipher. | |
59 | * | |
60 | * The cipher is reset each time this function is called. | |
61 | * Any previously retrieved input stream or in progress operation get discarded. | |
62 | * | |
63 | * @param is an input stream to filter. | |
64 | * @return a filtered input stream based on this cipher. | |
65 | */ | |
66 | FilterInputStream getInputStream(InputStream is); | |
67 | ||
68 | /** | |
69 | * Return a filtered output stream based on this cipher. | |
70 | * | |
71 | * The cipher is reset each time this function is called. | |
72 | * Any previously retrieved input stream or in progress operation get discarded. | |
73 | * | |
74 | * @param os an output stream to filter. | |
75 | * @return a filtered output stream based on this cipher. | |
76 | */ | |
77 | FilterOutputStream getOutputStream(OutputStream os); | |
78 | ||
79 | /** | |
80 | * Continues a multiple-part encryption or decryption operation, processing another data chunk. | |
81 | * | |
82 | * @param input the input buffer. | |
83 | * @return the new buffer with the result, or null if the underlying cipher is a block cipher and the input data is | |
84 | * too short to result in a new block. | |
85 | */ | |
86 | byte[] update(byte[] input); | |
87 | ||
88 | /** | |
89 | * Continues a multiple-part encryption or decryption operation processing another data chunk. | |
90 | * | |
91 | * @param input the input buffer. | |
92 | * @param inputOffset the offset in input where the input starts. | |
93 | * @param inputLen the input length. | |
94 | * @return the new buffer with the result, or null if the underlying cipher is a block cipher and the input data is | |
95 | * too short to result in a new block. | |
96 | */ | |
97 | byte[] update(byte[] input, int inputOffset, int inputLen); | |
98 | ||
99 | /** | |
100 | * Finishes a multiple-part encryption or decryption operation. | |
101 | * | |
102 | * Input data that may have been buffered during a previous update operation is processed, with padding | |
103 | * being applied. The result is stored in a new buffer. | |
104 | * | |
105 | * Upon finish, this method resets this cipher. | |
106 | * | |
107 | * @return the new buffer with the result. | |
108 | * @throws GeneralSecurityException if this encryption algorithm is unable to proceed properly. | |
109 | */ | |
110 | byte[] doFinal() throws GeneralSecurityException; | |
111 | ||
112 | /** | |
113 | * Encrypts or decrypts data in a one shot operation, or finishes a multiple-part operation. | |
114 | * | |
115 | * The bytes in the input buffer, and any input bytes that may have been buffered during a previous update | |
116 | * operation, are processed, with padding being applied. The result is stored in a new buffer. | |
117 | * | |
118 | * Upon finish, this method resets this cipher. | |
119 | * | |
120 | * @param input the input buffer. | |
121 | * @return the new buffer with the result. | |
122 | * @throws GeneralSecurityException if this encryption algorithm is unable to proceed properly. | |
123 | */ | |
124 | byte[] doFinal(byte[] input) throws GeneralSecurityException; | |
125 | ||
126 | ||
127 | /** | |
128 | * Encrypts or decrypts data in a one shot operation, or finishes a multiple-part operation. | |
129 | * | |
130 | * The first inputLen bytes in the input buffer, starting at inputOffset inclusive, and any input bytes that may | |
131 | * have been buffered during a previous update operation, are processed, with padding being applied. The result is | |
132 | * stored in a new buffer. | |
133 | * | |
134 | * Upon finish, this method resets this cipher. | |
135 | * | |
136 | * @param input the input buffer. | |
137 | * @param inputOffset the offset in input where the input starts. | |
138 | * @param inputLen the input length. | |
139 | * @return the new buffer with the result. | |
140 | * @throws GeneralSecurityException if this encryption algorithm is unable to proceed properly. | |
141 | */ | |
142 | byte[] doFinal(byte[] input, int inputOffset, int inputLen) throws GeneralSecurityException; | |
143 | } |