KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > crypto > NullCipherSpi


1 /*
2  * @(#)NullCipherSpi.java 1.8 04/01/06
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7  
8 package javax.crypto;
9
10 import java.security.*;
11 import java.security.spec.*;
12
13 /**
14  * This class provides a delegate for the identity cipher - one that does not
15  * tranform the plaintext.
16  *
17  * @author Li Gong
18  *
19  * @version 1.8, 01/06/04
20  *
21  * @see Nullcipher
22  *
23  * @since 1.4
24  */

25
26 final class NullCipherSpi extends CipherSpi {
27
28     /*
29      * Do not let anybody instantiate this directly (protected).
30      */

31     protected NullCipherSpi() {}
32
33     public void engineSetMode(String mode) {}
34
35     public void engineSetPadding(String padding) {}
36     
37     protected int engineGetBlockSize() {
38     return 1;
39     }
40     
41     protected int engineGetOutputSize(int inputLen) {
42     return inputLen;
43     }
44     
45     protected byte[] engineGetIV() {
46     byte[] x = new byte[8];
47     return x;
48     }
49
50     protected AlgorithmParameters engineGetParameters() {
51     return null;
52     }
53
54     protected void engineInit(int mode, Key key, SecureRandom random) {}
55
56     protected void engineInit(int mode, Key key,
57                   AlgorithmParameterSpec params,
58                   SecureRandom random) {}
59
60     protected void engineInit(int mode, Key key,
61                   AlgorithmParameters params,
62                   SecureRandom random) {}
63
64     protected byte[] engineUpdate(byte[] input, int inputOffset,
65                   int inputLen) {
66     if (input == null) return null;
67     byte[] x = new byte[inputLen];
68     System.arraycopy(input, inputOffset, x, 0, inputLen);
69     return x;
70     }
71     
72     protected int engineUpdate(byte[] input, int inputOffset,
73                    int inputLen, byte[] output,
74                    int outputOffset) {
75     if (input == null) return 0;
76     System.arraycopy(input, inputOffset, output, outputOffset, inputLen);
77     return inputLen;
78     }
79     
80     protected byte[] engineDoFinal(byte[] input, int inputOffset,
81                    int inputLen)
82     {
83     return engineUpdate(input, inputOffset, inputLen);
84     }
85     
86     protected int engineDoFinal(byte[] input, int inputOffset,
87                 int inputLen, byte[] output,
88                 int outputOffset)
89     {
90     return engineUpdate(input, inputOffset, inputLen,
91                 output, outputOffset);
92     }
93
94     protected int engineGetKeySize(Key key)
95     {
96     return 0;
97     }
98 }
99
Popular Tags