Version: 3.0 Update
This commit is contained in:
28
src/main/java/hae/utils/string/HashCalculator.java
Normal file
28
src/main/java/hae/utils/string/HashCalculator.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package hae.utils.string;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class HashCalculator {
|
||||
public static String calculateHash(byte[] bytes){
|
||||
MessageDigest digest;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
byte[] hashBytes = digest.digest(bytes);
|
||||
return bytesToHex(hashBytes);
|
||||
} catch (Exception ignored) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user