Class KeyUtils
java.lang.Object
org.wildfly.test.security.common.other.KeyUtils
Common methods for key-pair and X509 certificates generation.
- Author:
- Jan Stourac
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyPairGenerates key-pair withDEFAULT_KEY_ALGORITHMalgorithm andDEFAULT_KEY_SIZEkey size.static KeyPairgenerateKeyPair(String algorithm, int keySize) Generates key-pair with given algorithm and key size.static X509CertificategenerateX509Certificate(String name, KeyPair keyPair) Generates a self-signed certificate usingSIGNATURE_ALGORITHM.static X509CertificategenerateX509Certificate(String name, KeyPair keyPair, long certValidity, String signatureAlgorithm) Generates self-signed certificate for provided key-pair with given validity time and signature algorithm.
-
Constructor Details
-
KeyUtils
public KeyUtils()
-
-
Method Details
-
generateKeyPair
Generates key-pair withDEFAULT_KEY_ALGORITHMalgorithm andDEFAULT_KEY_SIZEkey size.- Returns:
- generated key-pair
- Throws:
NoSuchAlgorithmException
-
generateKeyPair
public static KeyPair generateKeyPair(String algorithm, int keySize) throws NoSuchAlgorithmException Generates key-pair with given algorithm and key size.- Parameters:
algorithm-keySize-- Returns:
- generated key-pair
- Throws:
NoSuchAlgorithmException
-
generateX509Certificate
public static X509Certificate generateX509Certificate(String name, KeyPair keyPair) throws CertificateException Generates a self-signed certificate usingSIGNATURE_ALGORITHM. The certificate will use a distinguished name of the formCN=nameand will be valid for 1 year.- Parameters:
name- common name for the certificatekeyPair- public and private keys- Returns:
- generated certificate
- Throws:
CertificateException
-
generateX509Certificate
public static X509Certificate generateX509Certificate(String name, KeyPair keyPair, long certValidity, String signatureAlgorithm) throws CertificateException Generates self-signed certificate for provided key-pair with given validity time and signature algorithm.- Parameters:
name- common name for the certificatekeyPair- public and private keyscertValidity- how long the certificate should be valid to the future (number of seconds)signatureAlgorithm- signature algorithm- Returns:
- generated certificate
- Throws:
CertificateException
-