|
|||||||||
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(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(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(String fileName,
int format)
Saves the private key and the certificate chain to a file using DER or PEM encoding. |
void |
writeTo(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(String fileName) throws 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 chainIOException
- if an error occurs when reading from the filepublic KeyAndCertificate(InputStream in) throws IOException
public KeyAndCertificate(byte[] bytes) throws IOException
public KeyAndCertificate(PrivateKey privateKey, X509Certificate[] certificateChain)
KeyAndCertificate
object from given private key and
X509 certificate chain.
privateKey
- the private keycertificateChain
- the X509 certificate chainMethod Detail |
public X509Certificate[] getCertificateChain()
KeyAndCertificate
object.public PrivateKey getPrivateKey()
KeyAndCertificate
object.public void writeTo(OutputStream os, int format) throws IOException
saveTo()
.public void saveTo(String fileName, int format) throws 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 failsNoSuchAlgorithmException
- if the key or key- encryption algorithm
is not supported
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |