Class PKCS8Key
java.lang.Object
org.mozilla.jss.netscape.security.pkcs.PKCS8Key
- All Implemented Interfaces:
Serializable
,Key
,PrivateKey
,Destroyable
- Direct Known Subclasses:
DSAPrivateKey
Holds a PKCS#8 key, for example a private key
- Version:
- 1.30, 97/12/10
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AlgorithmId
protected byte[]
protected byte[]
private static final long
use serialVersionUID from JDK 1.1.static final BigInteger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PKCS8Key
buildPKCS8Key
(AlgorithmId algid, byte[] key) private byte[]
copyEncodedKey
(byte[] encodedKey) void
decode
(byte[] encodedKey) void
decode
(InputStream in) Initialize an PKCS8Key object from an input stream.byte[]
encode()
Returns the DER-encoded form of the key as a byte array.final void
encode
(DerOutputStream out) PKCS#8 sequence on the DER output stream.(package private) static void
encode
(DerOutputStream out, AlgorithmId algid, byte[] key) boolean
Compares two private keys.Returns 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: "PKCS#8"int
hashCode()
Calculates a hash code value for this object.static PKCS8Key
Construct PKCS#8 subject public key from a DER value.protected void
Parse the key bits.private void
readObject
(ObjectInputStream stream) Serialization read ...toString()
private void
writeObject
(ObjectOutputStream stream) Serialization write ...Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.security.auth.Destroyable
destroy, isDestroyed
-
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 -
VERSION
-
-
Constructor Details
-
PKCS8Key
public PKCS8Key()Default constructor. The key constructed must have its key and algorithm initialized before it may be used, for example by usingdecode
.
-
-
Method Details
-
parse
Construct PKCS#8 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 PKCS8Key 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 thekey
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
anddecode
.- Throws:
IOException
- if a parsing error occurs.InvalidKeyException
- if the key encoding is invalid.
-
buildPKCS8Key
public static PKCS8Key buildPKCS8Key(AlgorithmId algid, byte[] key) throws IOException, InvalidKeyException - Throws:
IOException
InvalidKeyException
-
getAlgorithm
Returns the algorithm to be used with this key.- Specified by:
getAlgorithm
in interfaceKey
-
getAlgorithmId
Returns the algorithm ID to be used with this key. -
encode
PKCS#8 sequence on the DER output stream.- Throws:
IOException
-
getEncoded
public byte[] getEncoded()Returns the DER-encoded form of the key as a byte array.- Specified by:
getEncoded
in interfaceKey
-
getFormat
Returns the format for this key: "PKCS#8" -
encode
Returns the DER-encoded form of the key as a byte array.- Throws:
InvalidKeyException
- if an encoding error occurs.
-
toString
-
decode
Initialize an PKCS8Key object from an input stream. The data on that input stream must be encoded using DER, obeying the PKCS#8 format: a sequence consisting of a version, 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 thekey
member.- Parameters:
in
- an input stream with a DER-encoded PKCS#8 SubjectPublicKeyInfo value- Throws:
InvalidKeyException
- if a parsing error occurs.
-
decode
- Throws:
InvalidKeyException
-
writeObject
Serialization write ... PKCS#8 keys serialize as themselves, and they're parsed when they get read back.- Throws:
IOException
-
readObject
Serialization read ... PKCS#8 keys serialize as themselves, and they're parsed when they get read back.- Throws:
IOException
-
copyEncodedKey
private byte[] copyEncodedKey(byte[] encodedKey) -
encode
- Throws:
IOException
-
equals
Compares two private keys. This returns false if the object with which to compare is not of typeKey
. Otherwise, the encoding of this key object is compared with the encoding of the given key object. -
hashCode
public int hashCode()Calculates a hash code value for this object. Objects which are equal will also have the same hashcode.
-