Writing code to create a digital certificate with BouncyCastle.
Here is an important part of the problem causing the code.
public X509Certificate generateCertWithKeypair(KeyPair caPair)
throws InvalidKeyException, SecurityException, SignatureException {
X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();
v3CertGen
.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
v3CertGen
.setIssuerDN(new X509Principal("CN=cn, O=o, L=L, ST=il, C= c"));
v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60
* 60 * 24));
v3CertGen.setNotAfter(new Date(System.currentTimeMillis()
+ (1000L * 60 * 60 * 24 * 365 * 10)));
v3CertGen
.setSubjectDN(new X509Principal("CN=cn, O=o, L=L, ST=il, C= c"));
v3CertGen.setPublicKey(caPair.getPublic());
v3CertGen.setSignatureAlgorithm("SHA1WithRSAEncryption");
X509Certificate generateX509Certificate = v3CertGen
.generateX509Certificate(caPair.getPrivate());
return generateX509Certificate;
}
An exception
Exception in "main" java.lang.SecurityException: BC provider not installed!
at X509V3CertificateGenerator.generateX509Certificate(Unknown Source)
at chapter4.Dupe.generateCertWithKeypair(Dupe.java:74)
at chapter4.Dupe.main(Dupe.java:32)
In the search, I found that the last jar solves the problem, but no luck.
Did I miss something?
See the full code here.
source
share