3261N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Holds an X.509 key, for example a public key found in an X.509 0N/A * certificate. Includes a description of the algorithm to be used 0N/A * with the key; these keys normally are used as 0N/A * "SubjectPublicKeyInfo". 0N/A * <P>While this class can represent any kind of X.509 key, it may be 0N/A * desirable to provide subclasses which understand how to parse keying 0N/A * data. For example, RSA public keys have two members, one for the 0N/A * public modulus and one for the prime exponent. If such a class is 0N/A * provided, it is used when parsing X.509 keys. If one is not provided, 0N/A * the key still parses correctly. 0N/A * @author David Brownell 0N/A /** use serialVersionUID from JDK 1.1. for interoperability */ 0N/A /* The algorithm information (name, parameters, etc). */ 0N/A * The key bytes, without the algorithm information. 0N/A * @deprecated Use the BitArray form which does not require keys to 0N/A * @see sun.security.x509.X509Key#setKey(BitArray) 0N/A * @see sun.security.x509.X509Key#getKey() 0N/A * The number of bits unused in the last byte of the key. 0N/A * Added to keep the byte[] key form consistent with the BitArray 0N/A * form. Can de deleted when byte[] key is deleted. 0N/A /* BitArray form of key */ 0N/A /* The encoding for the key. */ 0N/A * Default constructor. The key constructed must have its key 0N/A * and algorithm initialized before it may be used, for example 0N/A * by using <code>decode</code>. 0N/A * Build and initialize as a "default" key. All X.509 key 0N/A * data is stored and transmitted losslessly, but no knowledge 0N/A * about this particular algorithm is available. 0N/A * Sets the key in the BitArray form. 0N/A * Do this to keep the byte array form consistent with 0N/A * this. Can delete when byte[] key is deleted. 0N/A * Gets the key. The key may or may not be byte aligned. 0N/A * @return a BitArray containing the key. 0N/A * Do this for consistency in case a subclass 0N/A * modifies byte[] key directly. Remove when 0N/A * byte[] key is deleted. 0N/A * Note: the consistency checks fail when the subclass 0N/A * modifies a non byte-aligned key (into a byte-aligned key) 0N/A * using the deprecated byte[] key field. 0N/A * Construct X.509 subject public key from a DER value. If 0N/A * the runtime environment is configured with a specific class for 0N/A * this kind of key, a subclass is returned. Otherwise, a generic 0N/A * X509Key object is returned. 0N/A * <P>This mechanism gurantees that keys (and algorithms) may be 0N/A * freely manipulated and transferred, without risk of losing 0N/A * information. Also, when a key (or algorithm) needs some special 0N/A * handling, that specific need can be accomodated. 0N/A * @param in the DER-encoded SubjectPublicKeyInfo value 0N/A * @exception IOException on data format errors 0N/A * Parse the key bits. This may be redefined by subclasses to take 0N/A * advantage of structure within the key. For example, RSA public 0N/A * keys encapsulate two unsigned integers (modulus and exponent) as 0N/A * DER values within the <code>key</code> bits; Diffie-Hellman and 0N/A * DSS/DSA keys encapsulate a single unsigned integer. 0N/A * <P>This function is called when creating X.509 SubjectPublicKeyInfo 0N/A * values using the X509Key member functions, such as <code>parse</code> 0N/A * and <code>decode</code>. 0N/A * @exception IOException on parsing errors. 0N/A * @exception InvalidKeyException on invalid key encodings. 0N/A * Factory interface, building the kind of key associated with this 0N/A * specific algorithm ID or else returning this generic base class. 0N/A * See the description above. 0N/A * Use the algid and key parameters to produce the ASN.1 encoding 0N/A * of the key, which will then be used as the input to the 0N/A // Instantiate the key factory of the appropriate algorithm 0N/A // Generate the public key 0N/A // Return generic X509Key with opaque key data (see below) 0N/A * Try again using JDK1.1-style for backwards compatibility. 0N/A // this should not happen. 0N/A * Returns the algorithm to be used with this key. 0N/A * Returns the algorithm ID to be used with this key. 0N/A * Encode SubjectPublicKeyInfo sequence on the DER output stream. 0N/A * @exception IOException on encoding errors. 0N/A * Returns the DER-encoded form of the key as a byte array. 0N/A * Returns the format for this key: "X.509" 0N/A * Returns the DER-encoded form of the key as a byte array. 0N/A * @exception InvalidKeyException on encoding errors. 0N/A * Returns a printable representation of the key 0N/A * Initialize an X509Key object from an input stream. The data on that 0N/A * input stream must be encoded using DER, obeying the X.509 0N/A * <code>SubjectPublicKeyInfo</code> format. That is, the data is a 0N/A * sequence consisting of an algorithm ID and a bit string which holds 0N/A * the key. (That bit string is often used to encapsulate another DER 0N/A * encoded sequence.) 0N/A * <P>Subclasses should not normally redefine this method; they should 0N/A * instead provide a <code>parseKeyBits</code> method to parse any 0N/A * fields inside the <code>key</code> member. 0N/A * <P>The exception to this rule is that since private keys need not 0N/A * be encoded using the X.509 <code>SubjectPublicKeyInfo</code> format, 0N/A * private keys may override this method, <code>encode</code>, and 0N/A * of course <code>getFormat</code>. 0N/A * @param in an input stream with a DER-encoded X.509 0N/A * SubjectPublicKeyInfo value 0N/A * @exception InvalidKeyException on parsing errors. 0N/A // e.printStackTrace (); 0N/A * Serialization write ... X.509 keys serialize as 0N/A * themselves, and they're parsed when they get read back. 0N/A * Serialization read ... X.509 keys serialize as 0N/A * themselves, and they're parsed when they get read back. 0N/A * Calculates a hash code value for the object. Objects 0N/A * which are equal will also have the same hashcode. 0N/A r += (
b1[i] &
0xff) *
37;
0N/A // should not happen 0N/A * Produce SubjectPublicKey encoding from algorithm id and key material.