public static X509Certificate generateX509V3RootCertificate(KeyPair pair)
throws NoSuchAlgorithmException, NoSuchProviderException,
CertificateEncodingException, InvalidKeyException,
IllegalStateException, SignatureException {
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
certGen.setIssuerDN(new X500Principal(
"CN=localhost, OU=Ldd600 Blog, O=SHA, C=cn"));
certGen.setNotBefore(new Date(System.currentTimeMillis() - 5000L));
certGen.setSubjectDN(new X500Principal(
"CN=localhost, OU=Ldd600 Blog, O=SHA, C=cn"));
certGen.setPublicKey(pair.getPublic());
certGen.setSignatureAlgorithm("SHA1WithRSA");
certGen.setNotAfter(new Date(System.currentTimeMillis()
+ Integer.MAX_VALUE));
return certGen.generate(pair.getPrivate(), new SecureRandom());
}
public static X500PrivateCredential createRootCredential(KeyPair rootPair)
throws Exception {
X509Certificate rootCert =
generateX509V3RootCertificate(rootPair);
return new X500PrivateCredential(rootCert, rootPair.getPrivate());
}
|