Created
January 5, 2023 13:28
-
-
Save queerzard/5304cc28080cbc6bdc0933a7a73de659 to your computer and use it in GitHub Desktop.
Hash Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String hash(String hashType, String inputHash) throws NoSuchAlgorithmException, IOException { | |
MessageDigest messageDigest = MessageDigest.getInstance(hashType); | |
messageDigest.update(inputHash.getBytes()); | |
byte[] digest = messageDigest.digest(); | |
StringBuffer stringBuffer = new StringBuffer(); | |
for (byte byt : digest) | |
stringBuffer.append(String.format("%02x", byt & 0xff)); | |
return stringBuffer.toString(); | |
} | |
@SneakyThrows public static String md5(String input){return hash("MD5", input);} | |
@SneakyThrows public static String sha1(String input){return hash("SHA-1", input);} | |
@SneakyThrows public static String sha256(String input){return hash("SHA-256", input);} | |
@SneakyThrows public static String sha384(String input){return hash("SHA-384", input);} | |
@SneakyThrows public static String sha512(String input){return hash("SHA-512", input);} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment