public final class SelfSignedCertificate
extends java.lang.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.
构造器和说明 |
---|
SelfSignedCertificate()
Creates a new instance.
|
SelfSignedCertificate(java.util.Date notBefore,
java.util.Date notAfter)
Creates a new instance.
|
SelfSignedCertificate(java.util.Date notBefore,
java.util.Date notAfter,
java.lang.String algorithm,
int bits)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn,
java.util.Date notBefore,
java.util.Date notAfter)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn,
java.util.Date notBefore,
java.util.Date notAfter,
java.lang.String algorithm,
int bits)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn,
java.security.SecureRandom random,
int bits)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn,
java.security.SecureRandom random,
int bits,
java.util.Date notBefore,
java.util.Date notAfter)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn,
java.security.SecureRandom random,
int bits,
java.util.Date notBefore,
java.util.Date notAfter,
java.lang.String algorithm)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn,
java.security.SecureRandom random,
java.lang.String algorithm,
int bits)
Creates a new instance.
|
SelfSignedCertificate(java.lang.String fqdn,
java.lang.String algorithm,
int bits)
Creates a new instance.
|
限定符和类型 | 方法和说明 |
---|---|
java.security.cert.X509Certificate |
cert()
Returns the generated X.509 certificate.
|
java.io.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.
|
java.security.PrivateKey |
key()
Returns the generated EC/RSA private key.
|
java.io.File |
privateKey()
Returns the generated EC/RSA private key file in PEM format.
|
public SelfSignedCertificate() throws java.security.cert.CertificateException
Algorithm: RSA
java.security.cert.CertificateException
public SelfSignedCertificate(java.util.Date notBefore, java.util.Date notAfter) throws java.security.cert.CertificateException
Algorithm: RSA
notBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timejava.security.cert.CertificateException
public SelfSignedCertificate(java.util.Date notBefore, java.util.Date notAfter, java.lang.String algorithm, int bits) throws java.security.cert.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 keyjava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn) throws java.security.cert.CertificateException
Algorithm: RSA
fqdn
- a fully qualified domain namejava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn, java.lang.String algorithm, int bits) throws java.security.cert.CertificateException
fqdn
- a fully qualified domain namealgorithm
- Key pair algorithmbits
- the number of bits of the generated private keyjava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn, java.util.Date notBefore, java.util.Date notAfter) throws java.security.cert.CertificateException
Algorithm: RSA
fqdn
- a fully qualified domain namenotBefore
- Certificate is not valid before this timenotAfter
- Certificate is not valid after this timejava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn, java.util.Date notBefore, java.util.Date notAfter, java.lang.String algorithm, int bits) throws java.security.cert.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 keyjava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn, java.security.SecureRandom random, int bits) throws java.security.cert.CertificateException
Algorithm: RSA
fqdn
- a fully qualified domain namerandom
- the SecureRandom
to usebits
- the number of bits of the generated private keyjava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn, java.security.SecureRandom random, java.lang.String algorithm, int bits) throws java.security.cert.CertificateException
fqdn
- a fully qualified domain namerandom
- the SecureRandom
to usealgorithm
- Key pair algorithmbits
- the number of bits of the generated private keyjava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn, java.security.SecureRandom random, int bits, java.util.Date notBefore, java.util.Date notAfter) throws java.security.cert.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 timejava.security.cert.CertificateException
public SelfSignedCertificate(java.lang.String fqdn, java.security.SecureRandom random, int bits, java.util.Date notBefore, java.util.Date notAfter, java.lang.String algorithm) throws java.security.cert.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 algorithmjava.security.cert.CertificateException
public java.io.File certificate()
public java.io.File privateKey()
public java.security.cert.X509Certificate cert()
public java.security.PrivateKey key()
public void delete()