Skip to content

Instantly share code, notes, and snippets.

@cyberpirate92
Created May 14, 2019 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberpirate92/796057fce252b4238d33e2f0111b0aab to your computer and use it in GitHub Desktop.
Save cyberpirate92/796057fce252b4238d33e2f0111b0aab to your computer and use it in GitHub Desktop.
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.nio.charset.StandardCharsets;
public class CryptoHelper {
public static String sha256(String text) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(text.getBytes(StandardCharsets.UTF_8));
byte[] hash = digest.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < hash.length; i++)
sb.append(Integer.toString((hash[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString().toUpperCase();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment