Package com.gmt2001.httpwsserver.x509
Class SelfSignedX509CertificateGenerator
java.lang.Object
com.gmt2001.httpwsserver.x509.SelfSignedX509CertificateGenerator
Generates a SelfSigned X.509 Certificate
Taken from https://stackoverflow.com/questions/1615871/creating-an-x509-certificate-in-java-without-bouncycastle Original code and modifications
by: Mike B, vbence, and Clark Hobbie
- Author:
- gmt2001
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final String
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic X509Certificate
generateCertificate
(String dn, KeyPair pair, int days, String algorithm) Create a self-signed X.509 Certificatestatic String
generateDistinguishedName
(String commonName) Generate a DN string with just the CNstatic KeyPair
generateKeyPair
(int keySize) Generate a Key Pair
-
Field Details
-
RECOMMENDED_KEY_SIZE
public static final int RECOMMENDED_KEY_SIZE- See Also:
-
RECOMMENDED_SIG_ALGO
- See Also:
-
RECOMMENDED_VALIDITY_DAYS
public static final int RECOMMENDED_VALIDITY_DAYS- See Also:
-
RECOMMENDED_RENEWAL_DAYS
public static final int RECOMMENDED_RENEWAL_DAYS- See Also:
-
-
Method Details
-
generateCertificate
public static X509Certificate generateCertificate(String dn, KeyPair pair, int days, String algorithm) throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException Create a self-signed X.509 Certificate- Parameters:
dn
- the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"pair
- the KeyPairdays
- how many days from now the Certificate is valid foralgorithm
- the signing algorithm, eg "SHA256withRSA"- Returns:
- the certificate
- Throws:
IOException
CertificateException
NoSuchAlgorithmException
InvalidKeyException
NoSuchProviderException
SignatureException
-
generateDistinguishedName
Generate a DN string with just the CN- Parameters:
commonName
- the Common Name- Returns:
- the formatted string
-
generateKeyPair
Generate a Key Pair- Parameters:
keySize
- the key size, in bits- Returns:
- the generated key pair
- Throws:
NoSuchAlgorithmException
-