Class SecurityManager
java.lang.Object
org.sentrysoftware.metricshub.engine.security.SecurityManager
Provides utility methods for encryption and decryption operations using a master key stored in a KeyStore.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic char[]Decrypts the given encrypted password using the master key stored in the KeyStore.static char[]Encrypts the given password using the master key stored in the KeyStore.static SecretKeygenerateMasterKey(@NonNull KeyStore ks, @lombok.NonNull char[] password, @NonNull File keyStoreFile) Generates and saves a new master key in the givenKeyStore.static KeyStoreloadKeyStore(@NonNull File keyStoreFile) Loads the KeyStore from the specified file, creating it if it does not exist.
-
Field Details
-
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:
KeyStoreinstance.- 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 givenKeyStore.- 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.
-