java.lang.Object
test.de.iip_ecosphere.platform.test.mqtt.hivemq.HiveMqHasher

public class HiveMqHasher extends Object
Utility class for generating secure password hashes and salts compatible with HiveMQ.

This implementation utilizes the PBKDF2 (Password-Based Key Derivation Function 2) algorithm with an HMAC-SHA-256 pseudo-random function. The resulting byte arrays are converted to Hexadecimal strings to match HiveMQ's standard configuration format.

* @author Gemini
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    The cryptographic algorithm family used for key derivation.
    private static final int
    The number of cryptographic iterations.
    private static final int
    The desired length of the derived key in bits.
    private static final int
    The length of the random salt in bytes (16 bytes = 128 bits).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Generates a cryptographically secure, random byte array to be used as a salt.
    static byte[]
    hashPassword(String password, byte[] salt)
    Hashes a plain-text password using the PBKDF2WithHmacSHA256 algorithm.
    static void
    main(String[] args)
    Application entry point demonstrating how to generate a HiveMQ-compatible salt and password hash.
    static String
    toHex(byte[] array)
    Converts a raw byte array into its equivalent lowercase Hexadecimal String representation.

    Methods inherited from class java.lang.Object

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

    • ALGORITHM

      private static final String ALGORITHM
      The cryptographic algorithm family used for key derivation.
      See Also:
    • ITERATIONS

      private static final int ITERATIONS
      The number of cryptographic iterations. HiveMQ defaults to 100 to prioritize high-throughput MQTT connection performance.
      See Also:
    • KEY_LENGTH

      private static final int KEY_LENGTH
      The desired length of the derived key in bits.
      See Also:
    • SALT_LENGTH

      private static final int SALT_LENGTH
      The length of the random salt in bytes (16 bytes = 128 bits).
      See Also:
  • Constructor Details

    • HiveMqHasher

      public HiveMqHasher()
  • Method Details

    • main

      public static void main(String[] args)
      Application entry point demonstrating how to generate a HiveMQ-compatible salt and password hash.
      Parameters:
      args - Command-line arguments (not used).
    • hashPassword

      public static byte[] hashPassword(String password, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException
      Hashes a plain-text password using the PBKDF2WithHmacSHA256 algorithm.
      Parameters:
      password - The plain-text password to be hashed.
      salt - The cryptographically secure random salt unique to the user.
      Returns:
      A byte[] representing the derived cryptographic key/hash.
      Throws:
      NoSuchAlgorithmException - If the PBKDF2WithHmacSHA256 algorithm is not available in the environment.
      InvalidKeySpecException - If the provided key specification is invalid for the SecretKeyFactory.
    • generateSalt

      public static byte[] generateSalt()
      Generates a cryptographically secure, random byte array to be used as a salt. Each user profile should always be assigned a unique salt.
      Returns:
      A byte[] array containing the generated salt bytes.
    • toHex

      public static String toHex(byte[] array)
      Converts a raw byte array into its equivalent lowercase Hexadecimal String representation. This utility matches the string format required by HiveMQ configuration files.
      Parameters:
      array - The byte[] array to convert.
      Returns:
      A hexadecimal String representation of the input byte array.