I have a program in Java which currently uses private JDK classes (CertAndKeyGen
and X500Name
) to generate self-signed X.509 certificates.
There are too many problems with this approach:
I would like to convert this code to use standard, supported JDK classes.
I have looked at using the ill-named CertificateFactory.generateCertificate()
methods, but no luck: they cannot generate any certificate, they are just able to load an existing one.
Does anybody know a standard JDK API that can generate a self-signed certificate?
This is as far as I could go:
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(2048, SecureRandom.getInstance("SHA1WithRSA"));
KeyPair keyPair = generator.generateKeyPair();
PrivateKey privatekey = keyPair.getPrivate();
X500Principal principal = new X500Principal(dn);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
// How to generate the self-signed certificate from there?
// certFactory.generate(inputStream) // only able to load an existing certificate
Note:
X509V3CertificateGenerator
keytool
via a ProcessBuilder
:)Ok, then I guess it does not exist.
The RFE I submitted to the JDK has been accepted and there is now an official bug for it: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8165481
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With