* 11 mars 07<br>
* @param args
*/
@SuppressWarnings("boxing")
public static void main(String[] args) {
CertificateGenerator certGenerator = new CertificateGenerator();
KeyStoreUtil keyStoreUtil = new KeyStoreUtil();
/*
* Sample : Create a ROOT and a NORMALIZE certificates and display their
* informations
*/
System.out.println("---[Bouncy Castle Sample]---");
try {
System.out.println("[Certificate Sample]");
// Create the ROOT certificate
System.out.print("Generate a ROOT certificate...");
RootCertificateVO rootCertificateVO = certGenerator
.createRootCertificate();
X509Certificate rootCertificate = rootCertificateVO
.getRootCertificate();
System.out.println("OK");
System.out.println("Certificate content :");
System.out.println(rootCertificate.toString());
System.out.print("Certificate is currently valid : ");
try {
rootCertificate.checkValidity();
System.out.println("YES");
} catch (CertificateExpiredException cee) {
System.out.printf("NO : %s\n", cee.getMessage());
} catch (CertificateNotYetValidException cnye) {
System.out.printf("NO : %s\n", cnye.getMessage());
}
System.out.println("--");
System.out.println("------");
System.out.println("--");
// Create the NORMALIZE certificate
System.out.print("Generate a NORMALIZE certificate...");
X509Certificate normalizeCertificate = certGenerator
.createNormalizeCertificate(rootCertificateVO);
System.out.println("OK");
System.out.println("Certificate content :");
System.out.println(normalizeCertificate.toString());
System.out.print("Certificate is currently valid : ");
try {
normalizeCertificate.checkValidity();
System.out.println("YES");
} catch (CertificateExpiredException cee) {
System.out.printf("NO : %s\n", cee.getMessage());
} catch (CertificateNotYetValidException cnye) {
System.out.printf("NO : %s\n", cnye.getMessage());
}
System.out.println("--");
System.out.println("------");
System.out.println("--");
// Write certificates objects to files
System.out.print("Write ROOT certificate object to a file...");
certGenerator.writeToFile(rootCertificate,
"RootCertificateTest.cer");
System.out.println("OK");
System.out.print("Write NORMALIZE certificate object to a file...");
certGenerator.writeToFile(normalizeCertificate,
"NormalizeCertificateTest.cer");
System.out.println("OK");
System.out.println("--");
System.out.println("------");