public static void generate(String subjectCn,
                                int validityDays,
                                String privateKeyPath,
                                String certificatePath) 
            throws Exception {

        // Ensure Bouncy Castle is registered as a security provider
        Security.addProvider(new BouncyCastleProvider());

        // 1) Generate an RSA 4096-bit key pair
        KeyPair keyPair = generateRsaKeyPair(4096);

        // 2) Generate a self-signed X.509 certificate
        X509Certificate certificate = generateSelfSignedCertificate(
                keyPair, subjectCn, validityDays);

        // 3) Write the private key (PEM) and the certificate (PEM) to files
        writePemFile(keyPair.getPrivate(), "PRIVATE KEY", privateKeyPath);
        writePemFile(certificate.getEncoded(), "CERTIFICATE", certificatePath);
    }
Generates a 4096-bit RSA key pair and a self-signed X.509 certificate (valid for 'validityDays' days),
with subject (and issuer) of "CN={subjectCn}".

Writes the private key to {@code privateKeyPath} and the certificate to {@code certificatePath},
both in PEM format.

@param subjectCn        The common name (CN) in the certificate (e.g. "cloud.vespa.example")
@param validityDays     How many days until this certificate expires
@param privateKeyPath   Destination file path for the private key PEM
@param certificatePath  Destination file path for the public certificate PEM
@throws Exception if anything goes wrong (IO, crypto errors, etc.)
integration/logstash-plugins/logstash-output-vespa/src/main/java/org/logstashplugins/SelfSignedCertGenerator.java