2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 * @author Boris V. Kuznetsov
22 package org.apache.harmony.crypto.tests.support;
24 import java.security.AlgorithmParameters;
25 import java.security.InvalidAlgorithmParameterException;
26 import java.security.InvalidKeyException;
27 import java.security.Key;
28 import java.security.NoSuchAlgorithmException;
29 import java.security.SecureRandom;
30 import java.security.spec.AlgorithmParameterSpec;
32 import javax.crypto.BadPaddingException;
33 import javax.crypto.CipherSpi;
34 import javax.crypto.IllegalBlockSizeException;
35 import javax.crypto.NoSuchPaddingException;
36 import javax.crypto.ShortBufferException;
40 * Cipher implementation for testing
42 public class MyCipher extends CipherSpi {
49 protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
53 protected void engineSetPadding(String padding)
54 throws NoSuchPaddingException {
55 if (!"PKCS5Padding".equals(padding)) {
56 throw new NoSuchPaddingException(padding);
61 protected int engineGetBlockSize() {
66 protected int engineGetOutputSize(int inputLen) {
71 protected byte[] engineGetIV() {
77 protected AlgorithmParameters engineGetParameters() {
82 protected void engineInit(int opmode, Key key, SecureRandom random)
83 throws InvalidKeyException {
87 protected void engineInit(int opmode, Key key,
88 AlgorithmParameterSpec params, SecureRandom random)
89 throws InvalidKeyException, InvalidAlgorithmParameterException {
93 protected void engineInit(int opmode, Key key, AlgorithmParameters params,
94 SecureRandom random) throws InvalidKeyException,
95 InvalidAlgorithmParameterException {
99 protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) {
104 protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
105 byte[] output, int outputOffset) throws ShortBufferException {
110 protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
111 throws IllegalBlockSizeException, BadPaddingException {
116 protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
117 byte[] output, int outputOffset) throws ShortBufferException,
118 IllegalBlockSizeException, BadPaddingException {