public final class SelfSignedCertificate extends Object
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.
An X.509 certificate file and a EC/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.
Constructor and Description |
---|
SelfSignedCertificate()
Creates a new instance.
|
SelfSignedCertificate(Date notBefore,
Date notAfter)
Creates a new instance.
|
SelfSignedCertificate(Date notBefore,
Date notAfter,
String algorithm,
int bits)
Creates a new instance.
|
SelfSignedCertificate(String fqdn)
Creates a new instance.
|
SelfSignedCertificate(String fqdn,
Date notBefore,
Date notAfter)
Creates a new instance.
|
SelfSignedCertificate(String fqdn,
Date notBefore,
Date notAfter,
String algorithm,
int bits)
Creates a new instance.
|
SelfSignedCertificate(String fqdn,
SecureRandom random,
int bits)
Creates a new instance.
|
SelfSignedCertificate(String fqdn,
SecureRandom random,
int bits,
Date notBefore,
Date notAfter)
Creates a new instance.
|
SelfSignedCertificate(String fqdn,
SecureRandom random,
int bits,
Date notBefore,
Date notAfter,
String algorithm)
Creates a new instance.
|
SelfSignedCertificate(String fqdn,
SecureRandom random,
String algorithm,
int bits)
Creates a new instance.
|
SelfSignedCertificate(String fqdn,
String algorithm,
int bits)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
X509Certificate |
cert()
Returns the generated X.509 certificate.
|
File |
certificate()
Returns the generated X.509 certificate file in PEM format.
|
void |
delete()
Deletes the generated X.509 certificate file and EC/RSA private key file.
|
PrivateKey |
key()
Returns the generated EC/RSA private key.
|
File |
privateKey()
Returns the generated EC/RSA private key file in PEM format.
|
public SelfSignedCertificate() throws CertificateException
Algorithm: RSA
CertificateException
public SelfSignedCertificate(Date notBefore, Date notAfter) throws CertificateException
Algorithm: RSA
notBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timeCertificateException
public SelfSignedCertificate(Date notBefore, Date notAfter, String algorithm, int bits) throws CertificateException
notBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timealgorithm
- Key pair algorithmbits
- the number of bits of the generated private keyCertificateException
public SelfSignedCertificate(String fqdn) throws CertificateException
Algorithm: RSA
fqdn
- a fully qualified domain nameCertificateException
public SelfSignedCertificate(String fqdn, String algorithm, int bits) throws CertificateException
fqdn
- a fully qualified domain namealgorithm
- Key pair algorithmbits
- the number of bits of the generated private keyCertificateException
public SelfSignedCertificate(String fqdn, Date notBefore, Date notAfter) throws CertificateException
Algorithm: RSA
fqdn
- a fully qualified domain namenotBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timeCertificateException
public SelfSignedCertificate(String fqdn, Date notBefore, Date notAfter, String algorithm, int bits) throws CertificateException
fqdn
- a fully qualified domain namenotBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timealgorithm
- Key pair algorithmbits
- the number of bits of the generated private keyCertificateException
public SelfSignedCertificate(String fqdn, SecureRandom random, int bits) throws CertificateException
Algorithm: RSA
fqdn
- a fully qualified domain namerandom
- the SecureRandom
to usebits
- the number of bits of the generated private keyCertificateException
public SelfSignedCertificate(String fqdn, SecureRandom random, String algorithm, int bits) throws CertificateException
fqdn
- a fully qualified domain namerandom
- the SecureRandom
to usealgorithm
- Key pair algorithmbits
- the number of bits of the generated private keyCertificateException
public SelfSignedCertificate(String fqdn, SecureRandom random, int bits, Date notBefore, Date notAfter) throws CertificateException
Algorithm: RSA
fqdn
- a fully qualified domain namerandom
- the SecureRandom
to usebits
- the number of bits of the generated private keynotBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timeCertificateException
public SelfSignedCertificate(String fqdn, SecureRandom random, int bits, Date notBefore, Date notAfter, String algorithm) throws CertificateException
fqdn
- a fully qualified domain namerandom
- the SecureRandom
to usebits
- the number of bits of the generated private keynotBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timealgorithm
- Key pair algorithmCertificateException
public File certificate()
public File privateKey()
public X509Certificate cert()
public PrivateKey key()
public void delete()
Copyright © 2008–2024 The Netty Project. All rights reserved.