Googling extension 2.5.29.15 will tell you what is related to KeyUsage
The source code X509V3CertificateGenerator for X509V3CertificateGenerator shows that addExtension() calls X509ExtensionsGenerator.addExtension() , which throws an exception if the added extension is already added.
The source code you provided above does just that, and an exception is thrown:
certGen.addExtension(X509Extensions.KeyUsage, true, new BasicConstraints(false)); certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
This is a bug in the code. You need to delete one of them. I would suggest that first.
source share