Class CryptoCipher
java.lang.Object
org.sentrysoftware.metricshub.engine.security.CryptoCipher
Utility class providing methods for encryption and decryption operations using AES/GCM/NoPadding algorithm.
The master key is stored as a Base64-encoded string and derived using PBKDF2WithHmacSHA512.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLength of the GCM initialization vector (IV) in bytes.static final intLength of the GCM authentication tag in bytes.static final intNumber of iterations for the PBKDF2 key derivation.static final intLength of the derived key in bytes.static final StringBase64-encoded string representation of the master key. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic char[]bytesToChars(byte[] bytes) Converts bytes to charsstatic byte[]charsToBytes(char[] chars) Converts chars to bytesstatic char[]Decrypt the given text value using a secreteKeystatic char[]Encrypts the given plaintext using the provided secret key.static char[]Generates a random master key.static byte[]getSalt()Gets a new random salt data.
-
Field Details
-
GCM_IV_LENGTH
public static final int GCM_IV_LENGTHLength of the GCM initialization vector (IV) in bytes.- See Also:
-
GCM_TAG_LENGTH
public static final int GCM_TAG_LENGTHLength of the GCM authentication tag in bytes.- See Also:
-
ITERATIONS
public static final int ITERATIONSNumber of iterations for the PBKDF2 key derivation.- See Also:
-
KEY_LENGTH
public static final int KEY_LENGTHLength of the derived key in bytes.- See Also:
-
MASTER_KEY
Base64-encoded string representation of the master key.- See Also:
-
-
Constructor Details
-
CryptoCipher
public CryptoCipher()
-
-
Method Details
-
generateRandomMasterKey
Generates a random master key.- Returns:
- Char array representing the generated master key.
- Throws:
MetricsHubSecurityException- If an error occurs during key generation.
-
getSalt
Gets a new random salt data.- Returns:
- A random salt used to safeguard the password.
- Throws:
NoSuchAlgorithmException- If algorithm used for salt generation does not exist.
-
encrypt
public static char[] encrypt(char[] plainText, SecretKey secretKey) throws MetricsHubSecurityException Encrypts the given plaintext using the provided secret key.- Parameters:
plainText- Plain text to be encrypted.secretKey- Secret key used for encryption.- Returns:
- Char array representing the encrypted data.
- Throws:
MetricsHubSecurityException- If an error occurs during encryption.
-
decrypt
Decrypt the given text value using a secreteKey- Parameters:
crypted- The text we wish to decryptsecretKey- TheSecretKeyinstance used to decrypt the text value- Returns:
- char array of decrypted data
-
charsToBytes
public static byte[] charsToBytes(char[] chars) Converts chars to bytes- Parameters:
chars- char array to convert- Returns:
- byte array
-
bytesToChars
public static char[] bytesToChars(byte[] bytes) Converts bytes to chars- Parameters:
bytes- byte array- Returns:
- char array
-