Skip to content

Instantly share code, notes, and snippets.

@TheMartinfer22
Created June 17, 2021 18:10
Show Gist options
  • Save TheMartinfer22/901c8108a6055f1b4a07836dc02fb282 to your computer and use it in GitHub Desktop.
Save TheMartinfer22/901c8108a6055f1b4a07836dc02fb282 to your computer and use it in GitHub Desktop.
HashUtils
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