|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--iaik.utils.KeyAndCertificate
A simple class for storing a private key and a certificate chain in one file.
The private key typically will be the private key belonging to the end entity´s public key being certified by the certificate located at the first position of the chain (e.g.. chain[0]).
This class may be used to build a KeyAndCertificate structure from
given private key and certificate chain, to store this structure in a file using
DER or PEM encoding, and to read in private key and certificate chain from the
file again.
Assuming to already have created a X509Certificate chain and a private key,
the following proceeding may be chosen for create a KeyAndCertificate
structure, save it to a file and read in the contents again:
// create a KeyAndCertificate structure from given private key and
// certificate chain and save it to a file using DER encoding:
KeyAndCertificate keyAndCert = new KeyAndCertificate(private_key, cert_chain);
keyAndCert.saveTo("key_and_cert.der", ASN1.DER);
// read in from file again:
KeyAndCertificate key_and_cert = new KeyAndCertificate("key_and_cert.der");
// obtain the private key:
PrivateKey priv_key = key_and_cert.getPrivateKey();
// obtain the certificate chain:
X509Certificate[] chain = key_and_cert.getCertificateChain();
| Constructor Summary | |
KeyAndCertificate(byte[] bytes)
Creates a KeyAndCertificate object from the given byte array. |
|
KeyAndCertificate(java.io.InputStream in)
Creates a KeyAndCertificate object from the given InputStream. |
|
KeyAndCertificate(PrivateKey privateKey,
X509Certificate[] certificateChain)
Creates a KeyAndCertificate object from given private key and
X509 certificate chain. |
|
KeyAndCertificate(java.lang.String fileName)
Creates a KeyAndCertificate object from a given file. |
|
| Method Summary | |
PrivateKey |
decrypt(char[] password)
Decrypts the private key in this KeyAndCertificate with the given password. |
void |
encrypt(char[] password,
AlgorithmID encryptionAlgorithm,
SecureRandom random)
Encrypt the private key with the specified password, the encryption algorithm and the specified random number generated. |
X509Certificate[] |
getCertificateChain()
Gets the certificate chain from this KeyAndCertificate object. |
PrivateKey |
getPrivateKey()
Gets the private key from this KeyAndCertificate object. |
boolean |
isEncrypted()
Test whether this KeyAndCertificate object contains an encrypted private key. |
void |
saveTo(java.lang.String fileName,
int format)
Saves the private key and the certificate chain to a file using DER or PEM encoding. |
void |
writeTo(java.io.OutputStream os,
int format)
Write the private key and the certificate chain to an OutputStream. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public KeyAndCertificate(java.lang.String fileName)
throws java.io.IOException
KeyAndCertificate object from a given file.
The given file supplies the KeyAndCertificate structure
in DER or PEM encoding format., e.g.:
KeyAndCertificate key_and_cert = new KeyAndCertificate("key_and_cert.der");
fileName - the name of the DER or PEM file from where to read in private key
and certificate chain
public KeyAndCertificate(java.io.InputStream in)
throws java.io.IOException
public KeyAndCertificate(byte[] bytes)
throws java.io.IOException
public KeyAndCertificate(PrivateKey privateKey,
X509Certificate[] certificateChain)
KeyAndCertificate object from given private key and
X509 certificate chain.
privateKey - the private keycertificateChain - the X509 certificate chain| Method Detail |
public X509Certificate[] getCertificateChain()
KeyAndCertificate object.public PrivateKey getPrivateKey()
KeyAndCertificate object.
public void writeTo(java.io.OutputStream os,
int format)
throws java.io.IOException
saveTo().
public void saveTo(java.lang.String fileName,
int format)
throws java.io.IOException
For instance:
KeyAndCertificate keyAndCert = new KeyAndCertificate(private_key, cert_chain);
keyAndCert.saveTo("key_and_cert.der", ASN1.DER);
fileName - the name of the file where the data shall be written toformat - the saving format (ASN1.DER or ASN1.PEM)public boolean isEncrypted()
public void encrypt(char[] password,
AlgorithmID encryptionAlgorithm,
SecureRandom random)
throws NoSuchAlgorithmException
public PrivateKey decrypt(char[] password)
throws NoSuchAlgorithmException
null if the decryption process fails
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||