|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--iaik.pkcs.pkcs8.PrivateKeyInfo
This class implements the PKCS#8 Private-Key Information Syntax Standard for storing private keys.
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.rsa.com/rsalabs/pubs/PKCS/index.html).
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 suppoert 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| Field Summary | |
protected AlgorithmID |
private_key_algorithm
Identifies the appertaining private-key algorithm. |
protected ASN1 |
private_key_info
|
| Fields inherited from interface java.security.PrivateKey |
serialVersionUID |
| Fields inherited from interface java.security.Key |
serialVersionUID |
| Constructor Summary | |
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. |
| Method Summary | |
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 PrivateKey |
getPrivateKey(ASN1Object privateKeyInfo)
Creates a PrivateKeyInfo from an ASN1Object. |
static 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. |
| Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
protected ASN1 private_key_info
protected AlgorithmID private_key_algorithm
| Constructor Detail |
protected PrivateKeyInfo()
public PrivateKeyInfo(ASN1Object obj)
throws InvalidKeyException
This constructor may be used for parsing an
already exisiting PrivateKeyInfo object, supplied as
ASN1Object that may have been created by calling
toASN1Object.
obj - the PrivateKeyInfo as ASN1Object
public PrivateKeyInfo(java.io.InputStream is)
throws 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 read
public PrivateKeyInfo(byte[] arr)
throws InvalidKeyException
This constructor may be used for parsing an
already exisiting 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 PrivateKeyInfo| Method Detail |
protected abstract void decode(byte[] privateKey)
throws InvalidKeyException
privateKey - the private key as DER encoded byte arrayprotected abstract byte[] encode()
public abstract java.lang.String getAlgorithm()
public 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.
obj - the PrivateKeyInfo as ASN1Objectprotected 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 PKCS#8 Private-Key Information Syntax Standard:
public static PrivateKey getPrivateKey(ASN1Object privateKeyInfo)
throws 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 exisiting
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 ASN1Object
public static PrivateKey getPrivateKey(byte[] privateKeyInfo)
throws 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 arraypublic ASN1Object toASN1Object()
public boolean equals(java.lang.Object obj)
public byte[] getEncoded()
public java.lang.String getFormat()
public void writeTo(java.io.OutputStream os)
throws java.io.IOException
os - the output streampublic java.lang.String toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||