Class SecurityManager

java.lang.Object
org.sentrysoftware.metricshub.engine.security.SecurityManager

public class SecurityManager extends Object
Provides utility methods for encryption and decryption operations using a master key stored in a KeyStore.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of the KeyStore file.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static char[]
    decrypt(char[] encrypted, File keyStoreFile)
    Decrypts the given encrypted password using the master key stored in the KeyStore.
    static char[]
    encrypt(char[] passwd, @NonNull File keyStoreFile)
    Encrypts the given password using the master key stored in the KeyStore.
    static SecretKey
    generateMasterKey(@NonNull KeyStore ks, @lombok.NonNull char[] password, @NonNull File keyStoreFile)
    Generates and saves a new master key in the given KeyStore.
    static KeyStore
    loadKeyStore(@NonNull File keyStoreFile)
    Loads the KeyStore from the specified file, creating it if it does not exist.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • METRICSHUB_KEY_STORE_FILE_NAME

      public static final String METRICSHUB_KEY_STORE_FILE_NAME
      Name of the KeyStore file.
      See Also:
  • Constructor Details

    • SecurityManager

      public SecurityManager()
  • Method Details

    • encrypt

      public static char[] encrypt(char[] passwd, @NonNull @NonNull File keyStoreFile) throws MetricsHubSecurityException
      Encrypts the given password using the master key stored in the KeyStore.
      Parameters:
      passwd - Password to encrypt.
      keyStoreFile - The KeyStore file holding secret information.
      Returns:
      Encrypted password as a char array.
      Throws:
      MetricsHubSecurityException - If an error occurs during encryption.
    • decrypt

      public static char[] decrypt(char[] encrypted, File keyStoreFile) throws MetricsHubSecurityException
      Decrypts the given encrypted password using the master key stored in the KeyStore.
      Parameters:
      encrypted - The encrypted text.
      keyStoreFile - The KeyStore file holding secret information.
      Returns:
      Decrypted password as a char array.
      Throws:
      MetricsHubSecurityException - If an error occurs during decryption.
    • loadKeyStore

      public static KeyStore loadKeyStore(@NonNull @NonNull File keyStoreFile) throws MetricsHubSecurityException
      Loads the KeyStore from the specified file, creating it if it does not exist.
      Parameters:
      keyStoreFile - The KeyStore file.
      Returns:
      KeyStore instance.
      Throws:
      MetricsHubSecurityException - If an error occurs during KeyStore loading or creation.
    • generateMasterKey

      public static SecretKey generateMasterKey(@NonNull @NonNull KeyStore ks, @NonNull @lombok.NonNull char[] password, @NonNull @NonNull File keyStoreFile) throws MetricsHubSecurityException
      Generates and saves a new master key in the given KeyStore.
      Parameters:
      ks - The KeyStore holding the secret key.
      password - The password used to protect the KeyStore.
      keyStoreFile - The KeyStore file.
      Returns:
      The newly generated SecretKey.
      Throws:
      MetricsHubSecurityException - If an error occurs during key generation or storage.