public abstract class PrivateKeyInfo extends java.lang.Object implements java.io.Serializable, ASN1Type, java.security.PrivateKey
A Private-key information according to PKCS#8 combines a private key (of a
public-key algorithm) and some attributes, which are used for developing trust
in information like public keys from top-level certification authorities (see
http://www.imc.org/rfc5208).
PKCS#8 defines PrivateKeyInfo as an ASN.1 SEQUENCE containing the
following components:
PrivateKeyInfo ::= SEQUENCE {
version Version,
privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
privateKey PrivateKey
attributes [0] IMPLICIT Attributes OPTIONAL }
where:
This class may be extended for every particular private key implemetation wishing to support PKCS#8 PrivateKeyInfo.Version ::= INTEGER -- Syntax Version Number PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier -- private key algorithm, e.g. rsaEncryption from PKCS#1 PrivateKey ::= OCTET STRING -- the value of the private key, e.g. a BER encoded RSAPrivateKey value Attributes ::= SET OF Attribute -- additional information, encrypted together with the private-key information
This class provides a variety of methods for creating, parsing, de- and encoding private key informations.
DHPrivateKey,
DSAPrivateKey,
RSAPrivateKey,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected AlgorithmID |
private_key_algorithm
Identifies the appertaining private-key algorithm.
|
protected ASN1 |
private_key_info |
| Modifier | Constructor and Description |
|---|---|
protected |
PrivateKeyInfo()
Default Constructor for derived classes.
|
|
PrivateKeyInfo(ASN1Object obj)
Creates a new PrivateKeyInfo from an ASN1Object.
|
|
PrivateKeyInfo(byte[] arr)
Creates a new PrivateKeyInfo from a byte array.
|
|
PrivateKeyInfo(java.io.InputStream is)
Creates a new PrivateKeyInfo from an InputStream.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
createPrivateKeyInfo()
Creates a PrivateKeyInfo ASN.1 data structure (PKCS#8).
|
void |
decode(ASN1Object obj)
Decodes the given ASN.1
PrivateKeyInfo object
for parsing the internal structure. |
protected abstract void |
decode(byte[] privateKey)
Abstract method to be implemented for decoding a DER encoded private key.
|
protected abstract byte[] |
encode()
Abstract method to be implemented for encoding this private key according
to DER.
|
boolean |
equals(java.lang.Object obj)
Compares this private key to another private key.
|
abstract java.lang.String |
getAlgorithm()
Returns the name of the algorithm.
|
byte[] |
getEncoded()
Returns this PrivateKeyInfo as a DER encoded ASN.1 data structure.
|
java.lang.String |
getFormat()
Returns the name of the encoding format..
|
static java.security.PrivateKey |
getPrivateKey(ASN1Object privateKeyInfo)
Creates a PrivateKeyInfo from an ASN1Object.
|
static java.security.PrivateKey |
getPrivateKey(byte[] privateKeyInfo)
Creates a PrivateKey from a DER encoded byte array in PKCS#8 PrivateKeyInfo format.
|
ASN1Object |
toASN1Object()
Returns this PrivateKeyInfo as ASN1Object.
|
java.lang.String |
toString()
Returns a string that represents the contents of this private key.
|
void |
writeTo(java.io.OutputStream os)
Writes this private key to an output stream.
|
protected ASN1 private_key_info
protected AlgorithmID private_key_algorithm
protected PrivateKeyInfo()
public PrivateKeyInfo(ASN1Object obj) throws java.security.InvalidKeyException
This constructor may be used for parsing an
already existing PrivateKeyInfo object, supplied as
ASN1Object that may have been created by calling
toASN1Object.
obj - the PrivateKeyInfo as ASN1Objectjava.security.InvalidKeyException - if the data can not be parsedpublic PrivateKeyInfo(java.io.InputStream is)
throws java.security.InvalidKeyException,
java.io.IOException
This constructor reads a PrivateKeyInfo previously written with
method writeTo.
This constructor cannot be used to read a serialized object.
is - the input stream from where the PrivateKeyInfo shall be readjava.security.InvalidKeyException - if the data can not be parsedjava.io.IOException - if an I/O error occurspublic PrivateKeyInfo(byte[] arr)
throws java.security.InvalidKeyException
This constructor may be used for parsing an
already existing PrivateKeyInfo object, supplied
as DER encoded ASN.1 structure, which may have been created
by calling the getEncoded
method of this class.
arr - the array containing the encoded PrivateKeyInfojava.security.InvalidKeyException - if the data can not be parsedprotected abstract void decode(byte[] privateKey)
throws java.security.InvalidKeyException
privateKey - the private key as DER encoded byte arrayjava.security.InvalidKeyException - if the does not match to the implemented
public-key algorithmprotected abstract byte[] encode()
public abstract java.lang.String getAlgorithm()
getAlgorithm in interface java.security.Keypublic void decode(ASN1Object obj) throws CodingException
PrivateKeyInfo object
for parsing the internal structure.
This method implements the ASN1Type interface and internally is called when
creating a PKCS#8 PrivateKeyInfo object from an
already existing PrivateKeyInfo object, supplied
as ASN1Object or DER encoded ASN1Object.
decode in interface ASN1Typeobj - the PrivateKeyInfo as ASN1ObjectCodingException - if the ASN1Object could not be parsedprotected void createPrivateKeyInfo()
This method is called by extending classes for creating a PrivateKeyInfo. This method creates a PrivateKeyInfo as an ASN.1 SEQUENCE object with components as specified in the Public-Key Cryptography Standards (PKCS) #8: Private-Key Information Syntax Specification Version 1.2 (RFC 5208):
public static java.security.PrivateKey getPrivateKey(ASN1Object privateKeyInfo) throws java.security.InvalidKeyException
This is a static method and therefore may be called for creating a PrivateKeyInfo from the given ASN1Object without explicitly instantiating this class, e.g:
PrivateKeyInfo priv_ki = PrivateKeyInfo.getPrivateKeyInfo(asn1_obj);
The given ASN1Object represents an already existing
PrivateKeyInfo object, and may have been created by calling
toASN1Object.
This method uses a KeyFactory for the registered algorithm to create the PrivateKeyInfo from the DER encoding of the supplied ASN1Object.
privateKeyInfo - the PrivateKeyInfo as ASN1Objectjava.security.InvalidKeyException - if the ASN1Object cannot be parsed or the inherent AlgorithmID does
not match to any implemented private-key algorithmpublic static java.security.PrivateKey getPrivateKey(byte[] privateKeyInfo)
throws java.security.InvalidKeyException
PrivateKey priv_ki = PrivateKeyInfo.getPrivateKey(key_array);
This method uses a KeyFactory for the registered algorithm to create the PrivateKey from the supplied DER encoded byte array.
privateKey - the PrivateKey as DER encoded byte arrayjava.security.InvalidKeyException - if the privateKey cannot be parsedpublic ASN1Object toASN1Object()
toASN1Object in interface ASN1Typepublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic byte[] getEncoded()
getEncoded in interface java.security.Keypublic java.lang.String getFormat()
getFormat in interface java.security.Keypublic void writeTo(java.io.OutputStream os)
throws java.io.IOException
os - the output streamjava.io.IOException - if an I/O error occurspublic java.lang.String toString()
toString in class java.lang.Object