public class X509Key
extends java.lang.Object
implements java.security.PublicKey
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.
Modifier and Type | Field and Description |
---|---|
protected AlgorithmId |
algid |
protected byte[] |
encodedKey |
protected byte[] |
key |
Constructor and Description |
---|
X509Key()
Default constructor.
|
X509Key(AlgorithmId algid,
byte[] key) |
Modifier and Type | Method and Description |
---|---|
void |
decode(byte[] encodedKey) |
void |
decode(java.io.InputStream in)
Initialize an X509Key object from an input stream.
|
byte[] |
encode()
Returns the DER-encoded form of the key as a byte array.
|
void |
encode(DerOutputStream out)
Encode SubjectPublicKeyInfo sequence on the DER output stream.
|
boolean |
equals(java.lang.Object object) |
java.lang.String |
getAlgorithm()
Returns the algorithm to be used with this key.
|
AlgorithmId |
getAlgorithmId()
Returns the algorithm ID to be used with this key.
|
byte[] |
getEncoded()
Returns the DER-encoded form of the key as a byte array.
|
java.lang.String |
getFormat()
Returns the format for this key: "X.509"
|
byte[] |
getKey()
Returns the raw key as a byte array
|
int |
hashCode()
Calculates a hash code value for the object.
|
static X509Key |
parse(DerValue in)
Construct X.509 subject public key from a DER value.
|
protected void |
parseKeyBits()
Parse the key bits.
|
static java.security.PublicKey |
parsePublicKey(DerValue in) |
java.lang.String |
toString() |
protected AlgorithmId algid
protected byte[] key
protected byte[] encodedKey
public X509Key()
decode
.public X509Key(AlgorithmId algid, byte[] key) throws java.security.InvalidKeyException
java.security.InvalidKeyException
public static X509Key parse(DerValue in) throws java.io.IOException
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.
in
- the DER-encoded SubjectPublicKeyInfo valuejava.io.IOException
- on data format errorsprotected void parseKeyBits() throws java.io.IOException, java.security.InvalidKeyException
key
bits; 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 parse
and decode
.
java.io.IOException
- on parsing errors.java.security.InvalidKeyException
- on invalid key encodings.public java.lang.String getAlgorithm()
getAlgorithm
in interface java.security.Key
public AlgorithmId getAlgorithmId()
public final void encode(DerOutputStream out) throws java.io.IOException
java.io.IOException
- on encoding errors.public byte[] getEncoded()
getEncoded
in interface java.security.Key
public java.lang.String getFormat()
getFormat
in interface java.security.Key
public byte[] getKey()
public byte[] encode() throws java.security.InvalidKeyException
java.security.InvalidKeyException
- on encoding errors.public java.lang.String toString()
toString
in class java.lang.Object
public void decode(java.io.InputStream in) throws java.security.InvalidKeyException
SubjectPublicKeyInfo
format. 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 parseKeyBits
method to parse any fields inside the key
member.
The exception to this rule is that since private keys need not be encoded using the X.509
SubjectPublicKeyInfo
format, private keys may override this method, encode
, and of
course getFormat
.
in
- an input stream with a DER-encoded X.509
SubjectPublicKeyInfo valuejava.security.InvalidKeyException
- on parsing errors.public void decode(byte[] encodedKey) throws java.security.InvalidKeyException
java.security.InvalidKeyException
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static java.security.PublicKey parsePublicKey(DerValue in) throws java.io.IOException
java.io.IOException