KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > crypto > spec > SecretKeySpec


1 /*
2  * @(#)SecretKeySpec.java 1.8 04/03/31
3  *
4  * Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7   
8 /*
9  * NOTE:
10  * Because of various external restrictions (i.e. US export
11  * regulations, etc.), the actual source code can not be provided
12  * at this time. This file represents the skeleton of the source
13  * file, so that javadocs of the API can be created.
14  */

15
16 package javax.crypto.spec;
17
18 import java.io.UnsupportedEncodingException;
19 import java.security.Key;
20 import java.security.spec.KeySpec;
21 import javax.crypto.SecretKey;
22
23 /**
24  * This class specifies a secret key in a provider-independent fashion.
25  *
26  * <p>It can be used to construct a <code>SecretKey</code> from a byte array,
27  * without having to go through a (provider-based)
28  * <code>SecretKeyFactory</code>.
29  *
30  * <p>This class is only useful for raw secret keys that can be represented as
31  * a byte array and have no key parameters associated with them, e.g., DES or
32  * Triple DES keys.
33  *
34  * @author Jan Luehe
35  *
36  * @version 1.24, 03/31/04
37  *
38  * @see javax.crypto.SecretKey
39  * @see javax.crypto.SecretKeyFactory
40  * @since 1.4
41  */

42 public class SecretKeySpec implements KeySpec, SecretKey
43 {
44     /**
45      * The secret key.
46      *
47      * @serial
48      */

49     private byte[] key;
50
51     /**
52      * The name of the algorithm associated with this key.
53      *
54      * @serial
55      */

56     private String algorithm;
57
58     /**
59      * Constructs a secret key from the given byte array.
60      *
61      * <p>This constructor does not check if the given bytes indeed specify a
62      * secret key of the specified algorithm. For example, if the algorithm is
63      * DES, this constructor does not check if <code>key</code> is 8 bytes
64      * long, and also does not check for weak or semi-weak keys.
65      * In order for those checks to be performed, an algorithm-specific
66      * <i>key specification</i> class (in this case:
67      * {@link DESKeySpec DESKeySpec})
68      * should be used.
69      *
70      * @param key the key material of the secret key. The contents of
71      * the array are copied to protect against subsequent modification.
72      * @param algorithm the name of the secret-key algorithm to be associated
73      * with the given key material.
74      * See Appendix A in the <a HREF="../../../../guide/security/jce/JCERefGuide.html">
75      * Java Cryptography Extension Reference Guide</a>
76      * for information about standard algorithm names.
77      * @exception IllegalArgumentException if <code>algorithm</code>
78      * is null or <code>key</code> is null or empty.
79      */

80     public SecretKeySpec(byte[] key, String algorithm) { }
81
82     /**
83      * Constructs a secret key from the given byte array, using the first
84      * <code>len</code> bytes of <code>key</code>, starting at
85      * <code>offset</code> inclusive.
86      *
87      * <p> The bytes that constitute the secret key are
88      * those between <code>key[offset]</code> and
89      * <code>key[offset+len-1]</code> inclusive.
90      *
91      * <p>This constructor does not check if the given bytes indeed specify a
92      * secret key of the specified algorithm. For example, if the algorithm is
93      * DES, this constructor does not check if <code>key</code> is 8 bytes
94      * long, and also does not check for weak or semi-weak keys.
95      * In order for those checks to be performed, an algorithm-specific key
96      * specification class (in this case:
97      * {@link DESKeySpec DESKeySpec})
98      * must be used.
99      *
100      * @param key the key material of the secret key. The first
101      * <code>len</code> bytes of the array beginning at
102      * <code>offset</code> inclusive are copied to protect
103      * against subsequent modification.
104      * @param offset the offset in <code>key</code> where the key material
105      * starts.
106      * @param len the length of the key material.
107      * @param algorithm the name of the secret-key algorithm to be associated
108      * with the given key material.
109      * See Appendix A in the <a HREF="../../../../guide/security/jce/JCERefGuide.html">
110      * Java Cryptography Extension Reference Guide</a>
111      * for information about standard algorithm names.
112      * @exception IllegalArgumentException if <code>algorithm</code>
113      * is null or <code>key</code> is null, empty, or too short,
114      * i.e. <code>key.length-offset<len</code>.
115      * @exception ArrayIndexOutOfBoundsException is thrown if
116      * <code>offset</code> or <code>len</code> index bytes outside the
117      * <code>key</code>.
118      */

119     public SecretKeySpec(byte[] key, int offset, int len, String algorithm) { }
120
121     /**
122      * Returns the name of the algorithm associated with this secret key.
123      *
124      * @return the secret key algorithm.
125      */

126     public String getAlgorithm() { }
127
128     /**
129      * Returns the name of the encoding format for this secret key.
130      *
131      * @return the string "RAW".
132      */

133     public String getFormat() { }
134
135     /**
136      * Returns the key material of this secret key.
137      *
138      * @return the key material. Returns a new array
139      * each time this method is called.
140      */

141     public byte[] getEncoded() { }
142
143     /**
144      * Calculates a hash code value for the object.
145      * Objects that are equal will also have the same hashcode.
146      */

147     public int hashCode() { }
148
149     /**
150      * Tests for equality between the specified object and this
151      * object. Two SecretKeySpec objects are considered equal if
152      * they are both SecretKey instances which have the
153      * same case-insensitive algorithm name and key encoding.
154      *
155      * @param obj the object to test for equality with this object.
156      *
157      * @return true if the objects are considered equal, false if
158      * <code>obj</code> is null or otherwise.
159      */

160     public boolean equals(Object obj) { }
161 }
162
Popular Tags