Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created February 12, 2015 15:52
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 bogdan/32e38b078a85c34eb315 to your computer and use it in GitHub Desktop.
Save bogdan/32e38b078a85c34eb315 to your computer and use it in GitHub Desktop.
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.io.UnsupportedEncodingException;
import java.security.*;
public class HelloWorld{
public static void main(String []args)
throws UnsupportedEncodingException, NoSuchAlgorithmException {
String digest = hash256("ef591fbbc527d77402d9a10dba92c195|approve-developer|developer@example.com|developer@example.com|2014-01-01T00:00:00+00:00");
System.out.println(digest);
}
public static String hash256(String data) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(data.getBytes());
return bytesToHex(md.digest());
}
public static String bytesToHex(byte[] bytes) {
StringBuffer result = new StringBuffer();
for (byte byt : bytes) result.append(Integer.toString((byt & 0xff) + 0x100, 16).substring(1));
return result.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment