01 /*
02 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
03 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04 *
05 * This code is free software; you can redistribute it and/or modify it
06 * under the terms of the GNU General Public License version 2 only, as
07 * published by the Free Software Foundation. Sun designates this
08 * particular file as subject to the "Classpath" exception as provided
09 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package java.security.spec;
27
28 /**
29 * This class represents a public or private key in encoded format.
30 *
31 * @author Jan Luehe
32 *
33 * @version 1.29, 05/05/07
34 *
35 * @see java.security.Key
36 * @see java.security.KeyFactory
37 * @see KeySpec
38 * @see X509EncodedKeySpec
39 * @see PKCS8EncodedKeySpec
40 *
41 * @since 1.2
42 */
43
44 public abstract class EncodedKeySpec implements KeySpec {
45
46 private byte[] encodedKey;
47
48 /**
49 * Creates a new EncodedKeySpec with the given encoded key.
50 *
51 * @param encodedKey the encoded key. The contents of the
52 * array are copied to protect against subsequent modification.
53 * @exception NullPointerException if <code>encodedKey</code>
54 * is null.
55 */
56 public EncodedKeySpec(byte[] encodedKey) {
57 this .encodedKey = (byte[]) encodedKey.clone();
58 }
59
60 /**
61 * Returns the encoded key.
62 *
63 * @return the encoded key. Returns a new array each time
64 * this method is called.
65 */
66 public byte[] getEncoded() {
67 return (byte[]) this .encodedKey.clone();
68 }
69
70 /**
71 * Returns the name of the encoding format associated with this
72 * key specification.
73 *
74 * <p>If the opaque representation of a key
75 * (see {@link java.security.Key Key}) can be transformed
76 * (see {@link java.security.KeyFactory KeyFactory})
77 * into this key specification (or a subclass of it),
78 * <code>getFormat</code> called
79 * on the opaque key returns the same value as the
80 * <code>getFormat</code> method
81 * of this key specification.
82 *
83 * @return a string representation of the encoding format.
84 */
85 public abstract String getFormat();
86 }
|