'Generate specific-length hash from a String using Java
I want to hash a String (with variable length) into a fixed-length String (the length can be specified) using Java programming language. The output hash is for unique-detection only, there are no security-requirement here. All characters from the result String should be equal in randomness. Please give me a efficient way to do this (an algorithm, an existing Java method, a library,... are all okay). Thank you!
PS: I want to give some example for clarification:
String message = "example message";
// hash(msg, length) is the method I want
// The output length can be specified in this method
String hash1 = hash(message, 5); // "s40j7"
String hash2 = hash(message, 8); // "orpx6klg"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
