Class X509Key
- All Implemented Interfaces:
Serializable,Key,PublicKey
- Direct Known Subclasses:
DSAPublicKey,RSAPublicKey
While this class can represent any kind of X.509 key, it may be desirable to provide subclasses which understand how to parse keying data. For example, RSA public keys have two members, one for the public modulus and one for the prime exponent. If such a class is provided, it is used when parsing X.509 keys. If one is not provided, the key still parses correctly.
- Version:
- 1.74, 97/12/10
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AlgorithmIdprotected byte[]protected byte[]private static final longuse serialVersionUID from JDK 1.1. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static PublicKeybuildPublicKey(AlgorithmId algid, byte[] key) (package private) static X509KeybuildX509Key(AlgorithmId algid, byte[] key) private byte[]copyEncodedKey(byte[] encodedKey) voiddecode(byte[] encodedKey) voiddecode(InputStream in) Initialize an X509Key object from an input stream.byte[]encode()Returns the DER-encoded form of the key as a byte array.final voidencode(DerOutputStream out) Encode SubjectPublicKeyInfo sequence on the DER output stream.(package private) static voidencode(DerOutputStream out, AlgorithmId algid, byte[] key) booleanReturns the algorithm to be used with this key.Returns the algorithm ID to be used with this key.byte[]Returns the DER-encoded form of the key as a byte array.Returns the format for this key: "X.509"byte[]getKey()Returns the raw key as a byte arrayinthashCode()Calculates a hash code value for the object.static X509KeyConstruct X.509 subject public key from a DER value.protected voidParse the key bits.static PublicKeyprivate voidreadObject(ObjectInputStream stream) Serialization read ...toString()private voidwriteObject(ObjectOutputStream stream) Serialization write ...
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDuse serialVersionUID from JDK 1.1. for interoperability- See Also:
-
algid
-
key
protected byte[] key -
encodedKey
protected byte[] encodedKey
-
-
Constructor Details
-
X509Key
public X509Key()Default constructor. The key constructed must have its key and algorithm initialized before it may be used, for example by usingdecode. -
X509Key
- Throws:
InvalidKeyException
-
-
Method Details
-
parse
Construct X.509 subject public key from a DER value. If the runtime environment is configured with a specific class for this kind of key, a subclass is returned. Otherwise, a generic X509Key object is returned.This mechanism gurantees that keys (and algorithms) may be freely manipulated and transferred, without risk of losing information. Also, when a key (or algorithm) needs some special handling, that specific need can be accomodated.
- Parameters:
in- the DER-encoded SubjectPublicKeyInfo value- Throws:
IOException- on data format errors
-
parseKeyBits
Parse the key bits. This may be redefined by subclasses to take advantage of structure within the key. For example, RSA public keys encapsulate two unsigned integers (modulus and exponent) as DER values within thekeybits; Diffie-Hellman and DSS/DSA keys encapsulate a single unsigned integer.This function is called when creating X.509 SubjectPublicKeyInfo values using the X509Key member functions, such as
parseanddecode.- Throws:
IOException- on parsing errors.InvalidKeyException- on invalid key encodings.
-
buildX509Key
- Throws:
IOExceptionInvalidKeyException
-
getAlgorithm
Returns the algorithm to be used with this key.- Specified by:
getAlgorithmin interfaceKey
-
getAlgorithmId
Returns the algorithm ID to be used with this key. -
encode
Encode SubjectPublicKeyInfo sequence on the DER output stream.- Throws:
IOException- on encoding errors.
-
getEncoded
public byte[] getEncoded()Returns the DER-encoded form of the key as a byte array.- Specified by:
getEncodedin interfaceKey
-
getFormat
Returns the format for this key: "X.509" -
getKey
public byte[] getKey()Returns the raw key as a byte array -
encode
Returns the DER-encoded form of the key as a byte array.- Throws:
InvalidKeyException- on encoding errors.
-
toString
-
decode
Initialize an X509Key object from an input stream. The data on that input stream must be encoded using DER, obeying the X.509SubjectPublicKeyInfoformat. That is, the data is a sequence consisting of an algorithm ID and a bit string which holds the key. (That bit string is often used to encapsulate another DER encoded sequence.)Subclasses should not normally redefine this method; they should instead provide a
parseKeyBitsmethod to parse any fields inside thekeymember.The exception to this rule is that since private keys need not be encoded using the X.509
SubjectPublicKeyInfoformat, private keys may override this method,encode, and of coursegetFormat.- Parameters:
in- an input stream with a DER-encoded X.509 SubjectPublicKeyInfo value- Throws:
InvalidKeyException- on parsing errors.
-
decode
- Throws:
InvalidKeyException
-
writeObject
Serialization write ... X.509 keys serialize as themselves, and they're parsed when they get read back.- Throws:
IOException
-
readObject
Serialization read ... X.509 keys serialize as themselves, and they're parsed when they get read back.- Throws:
IOException
-
equals
-
hashCode
public int hashCode()Calculates a hash code value for the object. Objects which are equal will also have the same hashcode. -
copyEncodedKey
private byte[] copyEncodedKey(byte[] encodedKey) -
encode
- Throws:
IOException
-
parsePublicKey
- Throws:
IOException
-
buildPublicKey
static PublicKey buildPublicKey(AlgorithmId algid, byte[] key) throws IOException, InvalidKeyException - Throws:
IOExceptionInvalidKeyException
-