1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.geronimo.util.crypto; 20 21 22 /** 23 * Block cipher engines are expected to conform to this interface. 24 */ 25 public interface BlockCipher 26 { 27 /** 28 * Initialise the cipher. 29 * 30 * @param forEncryption if true the cipher is initialised for 31 * encryption, if false for decryption. 32 * @param params the key and other data required by the cipher. 33 * @exception IllegalArgumentException if the params argument is 34 * inappropriate. 35 */ 36 public void init(boolean forEncryption, CipherParameters params) 37 throws IllegalArgumentException; 38 39 /** 40 * Return the name of the algorithm the cipher implements. 41 * 42 * @return the name of the algorithm the cipher implements. 43 */ 44 public String getAlgorithmName(); 45 46 /** 47 * Return the block size for this cipher (in bytes). 48 * 49 * @return the block size for this cipher in bytes. 50 */ 51 public int getBlockSize(); 52 53 /** 54 * Process one block of input from the array in and write it to 55 * the out array. 56 * 57 * @param in the array containing the input data. 58 * @param inOff offset into the in array the data starts at. 59 * @param out the array the output data will be copied into. 60 * @param outOff the offset into the out array the output will start at. 61 * @exception DataLengthException if there isn't enough data in in, or 62 * space in out. 63 * @exception IllegalStateException if the cipher isn't initialised. 64 * @return the number of bytes processed and produced. 65 */ 66 public int processBlock(byte[] in, int inOff, byte[] out, int outOff) 67 throws DataLengthException, IllegalStateException; 68 69 /** 70 * Reset the cipher. After resetting the cipher is in the same state 71 * as it was after the last init (if there was one). 72 */ 73 public void reset(); 74 }