//
//
// create the certificate - version 3
//
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(1));
certGen.setIssuerDN(new X509Principal(ord, values));
certGen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
certGen.setNotAfter(new Date(System.currentTimeMillis() + 50000));
certGen.setSubjectDN(new X509Principal(ord, values));
certGen.setPublicKey(pubKey);
certGen.setSignatureAlgorithm("SHA1withDSA");
try
{
X509Certificate cert = certGen.generate(privKey);
cert.checkValidity(new Date());
cert.verify(pubKey);
ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getEncoded());
CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC");
cert = (X509Certificate)fact.generateCertificate(bIn);
// System.out.println(cert);
}
catch (Exception e)
{
fail("error setting generating cert - " + e.toString());
}
//
// create the certificate - version 1
//
X509V1CertificateGenerator certGen1 = new X509V1CertificateGenerator();
certGen1.setSerialNumber(BigInteger.valueOf(1));
certGen1.setIssuerDN(new X509Principal(ord, values));
certGen1.setNotBefore(new Date(System.currentTimeMillis() - 50000));
certGen1.setNotAfter(new Date(System.currentTimeMillis() + 50000));
certGen1.setSubjectDN(new X509Principal(ord, values));
certGen1.setPublicKey(pubKey);
certGen1.setSignatureAlgorithm("SHA1withDSA");
try
{
X509Certificate cert = certGen1.generate(privKey);
cert.checkValidity(new Date());
cert.verify(pubKey);
ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getEncoded());
CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC");
cert = (X509Certificate)fact.generateCertificate(bIn);
//System.out.println(cert);
}
catch (Exception e)
{
fail("error setting generating cert - " + e.toString());
}
//
// exception test
//
try
{
certGen.setPublicKey(dudPublicKey);
fail("key without encoding not detected in v1");
}
catch (IllegalArgumentException e)
{