Class KeyStoreUtils

java.lang.Object
net.devh.boot.grpc.common.security.KeyStoreUtils

public final class KeyStoreUtils extends Object
Helper class to create KeyStore related components.
  • Field Details

  • Method Details

    • detectFormat

      public static String detectFormat(String format, String name)
      Detects the keystore format from the given keystore file name.
      Parameters:
      format - The format to base the decision on.
      name - The filename of the keystore.
      Returns:
      The detected keystore format. If unknown defaults to the systems default.
    • loadKeyManagerFactory

      public static KeyManagerFactory loadKeyManagerFactory(String keyStoreFormat, Resource keyStore, String keyStorePassword) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException
      Creates a new KeyManagerFactory from the given KeyStore Resource.
      Parameters:
      keyStoreFormat - The format of the keystore.
      keyStore - The resource containing the keystore.
      keyStorePassword - The password for the keystore. May be empty or null.
      Returns:
      The newly created KeyManagerFactory.
      Throws:
      KeyStoreException - If the keystore format isn't supported.
      IOException - If there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException
      NoSuchAlgorithmException - If the algorithm used to check the integrity of the keystore cannot be found
      CertificateException - If any of the certificates in the keystore could not be loaded
      UnrecoverableKeyException - If the key cannot be recovered(e.g. the given password is wrong).
    • loadTrustManagerFactory

      public static TrustManagerFactory loadTrustManagerFactory(String trustStoreFormat, Resource trustStore, String trustStorePassword) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException
      Creates a new TrustManagerFactory from the given KeyStore Resource.
      Parameters:
      trustStoreFormat - The format of the truststore.
      trustStore - The resource containing the truststore.
      trustStorePassword - The password for the truststore. May be empty or null.
      Returns:
      The newly created KeyManagerFactory.
      Throws:
      KeyStoreException - If the keystore format isn't supported.
      IOException - If there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the cause of the IOException should be an UnrecoverableKeyException
      NoSuchAlgorithmException - If the algorithm used to check the integrity of the keystore cannot be found
      CertificateException - If any of the certificates in the keystore could not be loaded