Class KeyUtils

java.lang.Object
org.wildfly.test.security.common.other.KeyUtils

public final class KeyUtils extends Object
Common methods for key-pair and X509 certificates generation.
Author:
Jan Stourac
  • Constructor Details

    • KeyUtils

      public KeyUtils()
  • Method Details

    • generateKeyPair

      public static KeyPair generateKeyPair() throws NoSuchAlgorithmException
      Generates key-pair with DEFAULT_KEY_ALGORITHM algorithm and DEFAULT_KEY_SIZE key 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 using SIGNATURE_ALGORITHM. The certificate will use a distinguished name of the form CN=name and will be valid for 1 year.
      Parameters:
      name - common name for the certificate
      keyPair - 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 certificate
      keyPair - public and private keys
      certValidity - how long the certificate should be valid to the future (number of seconds)
      signatureAlgorithm - signature algorithm
      Returns:
      generated certificate
      Throws:
      CertificateException