public class PKCS8Key
extends java.lang.Object
implements java.security.PrivateKey
| Modifier and Type | Field and Description |
|---|---|
protected AlgorithmId |
algid |
protected byte[] |
encodedKey |
protected byte[] |
key |
static java.math.BigInteger |
VERSION |
| Constructor and Description |
|---|
PKCS8Key()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static PKCS8Key |
buildPKCS8Key(AlgorithmId algid,
byte[] key) |
void |
decode(byte[] encodedKey) |
void |
decode(java.io.InputStream in)
Initialize an PKCS8Key object from an input stream.
|
byte[] |
encode()
Returns the DER-encoded form of the key as a byte array.
|
void |
encode(DerOutputStream out)
PKCS#8 sequence on the DER output stream.
|
boolean |
equals(java.lang.Object object)
Compares two private keys.
|
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: "PKCS#8"
|
int |
hashCode()
Calculates a hash code value for this object.
|
static PKCS8Key |
parse(DerValue in)
Construct PKCS#8 subject public key from a DER value.
|
protected void |
parseKeyBits()
Parse the key bits.
|
java.lang.String |
toString() |
protected AlgorithmId algid
protected byte[] key
protected byte[] encodedKey
public static final java.math.BigInteger VERSION
public PKCS8Key()
decode.public static PKCS8Key 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 PKCS#8 SubjectPublicKeyInfo values using the PKCS8Key member functions,
such as parse and decode.
java.io.IOException - if a parsing error occurs.java.security.InvalidKeyException - if the key encoding is invalid.public static PKCS8Key buildPKCS8Key(AlgorithmId algid, byte[] key) throws java.io.IOException, java.security.InvalidKeyException
java.io.IOExceptionjava.security.InvalidKeyExceptionpublic java.lang.String getAlgorithm()
getAlgorithm in interface java.security.Keypublic AlgorithmId getAlgorithmId()
public final void encode(DerOutputStream out) throws java.io.IOException
java.io.IOExceptionpublic byte[] getEncoded()
getEncoded in interface java.security.Keypublic java.lang.String getFormat()
getFormat in interface java.security.Keypublic byte[] encode()
throws java.security.InvalidKeyException
java.security.InvalidKeyException - if an encoding error occurs.public java.lang.String toString()
toString in class java.lang.Objectpublic void decode(java.io.InputStream in)
throws java.security.InvalidKeyException
Subclasses should not normally redefine this method; they should instead provide a parseKeyBits
method to parse any fields inside the key member.
in - an input stream with a DER-encoded PKCS#8
SubjectPublicKeyInfo valuejava.security.InvalidKeyException - if a parsing error occurs.public void decode(byte[] encodedKey)
throws java.security.InvalidKeyException
java.security.InvalidKeyExceptionpublic boolean equals(java.lang.Object object)
Key.
Otherwise, the encoding of this key object is compared with the
encoding of the given key object.equals in class java.lang.Objectobject - the object with which to comparetrue if this key has the same encoding as the
object argument; false otherwise.public int hashCode()
hashCode in class java.lang.Object