Class CryptoCipher

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

public class CryptoCipher extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Length of the GCM initialization vector (IV) in bytes.
    static final int
    Length of the GCM authentication tag in bytes.
    static final int
    Number of iterations for the PBKDF2 key derivation.
    static final int
    Length of the derived key in bytes.
    static final String
    Base64-encoded string representation of the master key.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static char[]
    bytesToChars(byte[] bytes)
    Converts bytes to chars
    static byte[]
    charsToBytes(char[] chars)
    Converts chars to bytes
    static char[]
    decrypt(char[] crypted, SecretKey secretKey)
    Decrypt the given text value using a secreteKey
    static char[]
    encrypt(char[] plainText, SecretKey secretKey)
    Encrypts the given plaintext using the provided secret key.
    static char[]
    Generates a random master key.
    static byte[]
    Gets a new random salt data.

    Methods inherited from class java.lang.Object

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

    • GCM_IV_LENGTH

      public static final int GCM_IV_LENGTH
      Length of the GCM initialization vector (IV) in bytes.
      See Also:
    • GCM_TAG_LENGTH

      public static final int GCM_TAG_LENGTH
      Length of the GCM authentication tag in bytes.
      See Also:
    • ITERATIONS

      public static final int ITERATIONS
      Number of iterations for the PBKDF2 key derivation.
      See Also:
    • KEY_LENGTH

      public static final int KEY_LENGTH
      Length of the derived key in bytes.
      See Also:
    • MASTER_KEY

      public static final String MASTER_KEY
      Base64-encoded string representation of the master key.
      See Also:
  • Constructor Details

    • CryptoCipher

      public CryptoCipher()
  • Method Details

    • generateRandomMasterKey

      public static char[] generateRandomMasterKey() throws MetricsHubSecurityException
      Generates a random master key.
      Returns:
      Char array representing the generated master key.
      Throws:
      MetricsHubSecurityException - If an error occurs during key generation.
    • getSalt

      public static byte[] getSalt() throws NoSuchAlgorithmException
      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

      public static char[] decrypt(char[] crypted, SecretKey secretKey)
      Decrypt the given text value using a secreteKey
      Parameters:
      crypted - The text we wish to decrypt
      secretKey - The SecretKey instance 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