1/*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.security.spec;
27
28/**
29 * This class represents the ASN.1 encoding of a private key,
30 * encoded according to the ASN.1 type {@code PrivateKeyInfo}.
31 * The {@code PrivateKeyInfo} syntax is defined in the PKCS#8 standard
32 * as follows:
33 *
34 * <pre>
35 * PrivateKeyInfo ::= SEQUENCE {
36 *   version Version,
37 *   privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
38 *   privateKey PrivateKey,
39 *   attributes [0] IMPLICIT Attributes OPTIONAL }
40 *
41 * Version ::= INTEGER
42 *
43 * PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
44 *
45 * PrivateKey ::= OCTET STRING
46 *
47 * Attributes ::= SET OF Attribute
48 * </pre>
49 *
50 * @author Jan Luehe
51 *
52 *
53 * @see java.security.Key
54 * @see java.security.KeyFactory
55 * @see KeySpec
56 * @see EncodedKeySpec
57 * @see X509EncodedKeySpec
58 *
59 * @since 1.2
60 */
61
62public class PKCS8EncodedKeySpec extends EncodedKeySpec {
63
64    /**
65     * Creates a new PKCS8EncodedKeySpec with the given encoded key.
66     *
67     * @param encodedKey the key, which is assumed to be
68     * encoded according to the PKCS #8 standard. The contents of
69     * the array are copied to protect against subsequent modification.
70     * @exception NullPointerException if {@code encodedKey}
71     * is null.
72     */
73    public PKCS8EncodedKeySpec(byte[] encodedKey) {
74        super(encodedKey);
75    }
76
77    /**
78     * Returns the key bytes, encoded according to the PKCS #8 standard.
79     *
80     * @return the PKCS #8 encoding of the key. Returns a new array
81     * each time this method is called.
82     */
83    public byte[] getEncoded() {
84        return super.getEncoded();
85    }
86
87    /**
88     * Returns the name of the encoding format associated with this
89     * key specification.
90     *
91     * @return the string {@code "PKCS#8"}.
92     */
93    public final String getFormat() {
94        return "PKCS#8";
95    }
96}
97