Class HiveMqHasher
java.lang.Object
test.de.iip_ecosphere.platform.test.mqtt.hivemq.HiveMqHasher
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
FieldsModifier and TypeFieldDescriptionprivate static final StringThe cryptographic algorithm family used for key derivation.private static final intThe number of cryptographic iterations.private static final intThe desired length of the derived key in bits.private static final intThe length of the random salt in bytes (16 bytes = 128 bits). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 voidApplication entry point demonstrating how to generate a HiveMQ-compatible salt and password hash.static StringtoHex(byte[] array) Converts a raw byte array into its equivalent lowercase Hexadecimal String representation.
-
Field Details
-
ALGORITHM
The cryptographic algorithm family used for key derivation.- See Also:
-
ITERATIONS
private static final int ITERATIONSThe number of cryptographic iterations. HiveMQ defaults to 100 to prioritize high-throughput MQTT connection performance.- See Also:
-
KEY_LENGTH
private static final int KEY_LENGTHThe desired length of the derived key in bits.- See Also:
-
SALT_LENGTH
private static final int SALT_LENGTHThe length of the random salt in bytes (16 bytes = 128 bits).- See Also:
-
-
Constructor Details
-
HiveMqHasher
public HiveMqHasher()
-
-
Method Details
-
main
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
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- Thebyte[]array to convert.- Returns:
- A hexadecimal
Stringrepresentation of the input byte array.
-