private static X509Certificate signCertificate(X509v3CertificateBuilder certificateBuilder,
            PrivateKey signedWithPrivateKey) throws OperatorCreationException,
            CertificateException {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            ContentSigner signer = new JcaContentSignerBuilder(SIGNATURE_ALGORITHM)
                    .build(signedWithPrivateKey);
            return new JcaX509CertificateConverter()
                    .getCertificate(certificateBuilder.build(signer));
        } else {
            ContentSigner signer = new JcaContentSignerBuilder(SIGNATURE_ALGORITHM)
                    .setProvider(PROVIDER_NAME)
                    .build(signedWithPrivateKey);
            return new JcaX509CertificateConverter()
                    .setProvider(PROVIDER_NAME)
                    .getCertificate(certificateBuilder.build(signer));
        }
    }
Generate a root keystore by a given {@link JKS}.

@param jks A java keystore object.
@return A root {@link KeyStore}.
netbare-core/src/main/java/com/github/megatronking/netbare/ssl/CertificateGenerator.java