Class SelfSignedCertificate


  • public final class SelfSignedCertificate
    extends Object
    Generates a temporary self-signed certificate for testing purposes.

    NOTE: Never use the certificate and private key generated by this class in production. It is purely for testing purposes, and thus it is very insecure. It even uses an insecure pseudo-random generator for faster generation internally.

    A X.509 certificate file and a RSA private key file are generated in a system's temporary directory using File.createTempFile(String, String), and they are deleted when the JVM exits using File.deleteOnExit().

    At first, this method tries to use OpenJDK's X.509 implementation (the sun.security.x509 package). If it fails, it tries to use Bouncy Castle as a fallback.

    • Method Detail

      • certificate

        public File certificate()
        Returns the generated X.509 certificate file in PEM format.
      • privateKey

        public File privateKey()
        Returns the generated RSA private key file in PEM format.
      • delete

        public void delete()
        Deletes the generated X.509 certificate file and RSA private key file.