|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--demo.x509.CreateDemoCerts
Creates certificate chains for some demo applications and writes them - together with the actual subject´s private key - into several .PEM (Base64 encoded DER format) files. Creates some test certificate chains and writes them into .PEM files.
This class creates a - if not already existing - "test" sub-directory of the current working directory for writing the PEM encoded test certificate chains to it. Each chain is stored together with the the private key belonging to the subject´s certificate, which is located at index 0 of the chain.
This class creates two CA certificates and four user certificates. The
CA certificate chains only hold the corresponding CA certificates, whereas
the user certificate chains contain the user (subject) certificate at index
0 and the CA certificate at index 1. The private key giving a
KeyAndCertificate
structure together with the actual certificate
chain, in any case belongs to the certificate at index 0. All generated
keys have a modulus length of 1024 bits. Since the keys actually are
generated during program execution, running this class will take
a certain amount of time.
The following certificates (and keys) are created and saved to files:
Constructor Summary | |
CreateDemoCerts()
|
Method Summary | |
X509Certificate |
createCertificate(Name subject,
PublicKey pk,
Name issuer,
PrivateKey sk,
AlgorithmID algorithm,
int serialNumber,
V3Extension[] extensions)
Creates a test certificate according to the X.509 Notation. |
KeyPair |
generateKeyPair(String algorithm,
int bits)
Generates a Key pair for the requested public key algorithm. |
static void |
main(String[] arg)
Starts the certificate creation process. |
void |
saveKeyAndCert(KeyPair keyPair,
X509Certificate[] chain,
String fileName)
Saves the private key and the certificate chain into one file. |
void |
start()
Creates some test certificate chains and writes them into .PEM files. |
void |
verifyCertificate(X509Certificate userCert,
X509Certificate caCert)
Verifies the digital signature of a certificate. |
void |
verifyCertificateChain(X509Certificate[] certs)
Verifies a chain of certificates where the user certificate is stored at index 0. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CreateDemoCerts()
Method Detail |
public void saveKeyAndCert(KeyPair keyPair, X509Certificate[] chain, String fileName) throws IOException
keyPair
- the keyPair from which to get the private key to be written
to the specified filechain
- the chain of X509 certificates to be written to the specified
filefilename
- the name of the file to which private key and certificates
shall be writtenIOException
- if an error occurs when writing to the filepublic KeyPair generateKeyPair(String algorithm, int bits) throws Exception
algorithm
- the public key algorithmbits
- the length of the key (modulus) in bitsNoSuchAlgorithmException
- if the requested algorithm is not implementedpublic void verifyCertificateChain(X509Certificate[] certs) throws Exception
certs[0] = user certificate. certs[x] = self signed CA certificate
certs
- the certificate chain to verifypublic void verifyCertificate(X509Certificate userCert, X509Certificate caCert) throws Exception
userCert
- the certificate to verifycaCert
- the certificate of the CA which has issued the userCert
or null
if the userCert is a self signed certificatepublic X509Certificate createCertificate(Name subject, PublicKey pk, Name issuer, PrivateKey sk, AlgorithmID algorithm, int serialNumber, V3Extension[] extensions) throws Exception
Depending on the subject ID either a self-signed CA certificate will be created or a user certificate.
subject
- the user demanding the certificate (may be the certification
authority itself)pk
- the subject´s public key to be certifiedissuer
- the certification authority that issues the certificatesk
- the issuer´s private key for signing the certificatealgorithm
- the ID of the signature algorithmserialNumber
- the issuer-specific serial number of the certificateCertificateException
- if the certificate cannot be createdpublic void start()
This method creates a - if not already existing - "test" sub-directory of the current working directory for writing the PEM encoded test certificate chains to it. Each chain is stored together with the the private key belonging to the subject´s certificate, which is located at index 0 of the chain.
This method creates two CA certificates and four user certificates. The
CA certificate chains only hold the corresponding CA certificates, whereas
the user certificate chains contain the user (subject) certificate at index
0 and the CA certificate at index 1. The private key giving a
KeyAndCertificate
structure together with the actual certificate
chain, in any case belongs to the certificate at index 0. All generated
keys have a modulus length of 1024 bits.
The following certificates (and keys) are created and saved to files:
true
if the generation was ok,
false
otherwisepublic static void main(String[] arg) throws IOException
I/O
- Exception an I/O error occurs when writing ti files
|
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 |