src/share/classes/java/security/spec/X509EncodedKeySpec.java

Print this page




  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</code>.
  31  * The <code>SubjectPublicKeyInfo</code> 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 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      * @exception NullPointerException if <code>encodedKey</code>
  61      * is null.
  62      */
  63     public X509EncodedKeySpec(byte[] encodedKey) {
  64         super(encodedKey);
  65     }
  66 
  67     /**
  68      * Returns the key bytes, encoded according to the X.509 standard.
  69      *
  70      * @return the X.509 encoding of the key. Returns a new array
  71      * each time this method is called.
  72      */
  73     public byte[] getEncoded() {
  74         return super.getEncoded();
  75     }
  76 
  77     /**
  78      * Returns the name of the encoding format associated with this
  79      * key specification.
  80      *
  81      * @return the string <code>"X.509"</code>.
  82      */
  83     public final String getFormat() {
  84         return "X.509";
  85     }
  86 }


  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 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      * @exception NullPointerException if {@code encodedKey}
  61      * is null.
  62      */
  63     public X509EncodedKeySpec(byte[] encodedKey) {
  64         super(encodedKey);
  65     }
  66 
  67     /**
  68      * Returns the key bytes, encoded according to the X.509 standard.
  69      *
  70      * @return the X.509 encoding of the key. Returns a new array
  71      * each time this method is called.
  72      */
  73     public byte[] getEncoded() {
  74         return super.getEncoded();
  75     }
  76 
  77     /**
  78      * Returns the name of the encoding format associated with this
  79      * key specification.
  80      *
  81      * @return the string {@code "X.509"}.
  82      */
  83     public final String getFormat() {
  84         return "X.509";
  85     }
  86 }