1 /*
   2  * Copyright (c) 1997, 2014, 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 
  26 package java.security.spec;
  27 
  28 /**
  29  * This class represents the ASN.1 encoding of a public key,
  30  * encoded according to the ASN.1 type {@code SubjectPublicKeyInfo}.
  31  * The {@code SubjectPublicKeyInfo} syntax is defined in the X.509
  32  * standard as follows:
  33  *
  34  * <pre>
  35  * SubjectPublicKeyInfo ::= SEQUENCE {
  36  *   algorithm AlgorithmIdentifier,
  37  *   subjectPublicKey BIT STRING }
  38  * </pre>
  39  *
  40  * @author Jan Luehe
  41  *
  42  *
  43  * @see java.security.Key
  44  * @see java.security.KeyFactory
  45  * @see KeySpec
  46  * @see EncodedKeySpec
  47  * @see PKCS8EncodedKeySpec
  48  *
  49  * @since 1.2
  50  */
  51 
  52 public class X509EncodedKeySpec extends EncodedKeySpec {
  53 
  54     /**
  55      * Creates a new {@code X509EncodedKeySpec} with the given encoded key.
  56      *
  57      * @param encodedKey the key, which is assumed to be
  58      * encoded according to the X.509 standard. The contents of the
  59      * array are copied to protect against subsequent modification.
  60      * @throws NullPointerException if {@code encodedKey}
  61      * is null.
  62      */
  63     public X509EncodedKeySpec(byte[] encodedKey) {
  64         super(encodedKey);
  65     }
  66 
  67     /**
  68      * Creates a new {@code X509EncodedKeySpec} with the given encoded key.
  69      * This constructor is useful when subsequent callers of the
  70      * {@code X509EncodedKeySpec} object might not know the algorithm
  71      * of the key.
  72      *
  73      * @param encodedKey the key, which is assumed to be
  74      * encoded according to the X.509 standard. The contents of the
  75      * array are copied to protect against subsequent modification.
  76      * @param algorithm the algorithm name of the encoded public key
  77      * See the KeyFactory section in the <a href=
  78      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyFactory">
  79      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
  80      * for information about standard algorithm names.
  81      * @throws NullPointerException if {@code encodedKey}
  82      * or {@code algorithm} is null.
  83      * @throws IllegalArgumentException if {@code algorithm} is
  84      * the empty string {@code ""}
  85      * @since 9
  86      */
  87     public X509EncodedKeySpec(byte[] encodedKey, String algorithm) {
  88         super(encodedKey, algorithm);
  89     }
  90 
  91     /**
  92      * Returns the key bytes, encoded according to the X.509 standard.
  93      *
  94      * @return the X.509 encoding of the key. Returns a new array
  95      * each time this method is called.
  96      */
  97     public byte[] getEncoded() {
  98         return super.getEncoded();
  99     }
 100 
 101     /**
 102      * Returns the name of the encoding format associated with this
 103      * key specification.
 104      *
 105      * @return the string {@code "X.509"}.
 106      */
 107     public final String getFormat() {
 108         return "X.509";
 109     }
 110 }