Created
June 17, 2021 18:10
-
-
Save TheMartinfer22/901c8108a6055f1b4a07836dc02fb282 to your computer and use it in GitHub Desktop.
HashUtils
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
import java.nio.charset.StandardCharsets; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
public class HashUtils { | |
public String hash(String input) throws NoSuchAlgorithmException { | |
MessageDigest hash = MessageDigest.getInstance("SHA-1"); | |
hash.update(input.getBytes(StandardCharsets.UTF_8)); | |
StringBuilder sb = new StringBuilder(); | |
for (byte b : hash.digest()){ | |
sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); | |
} | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment