Created
February 12, 2015 15:52
-
-
Save bogdan/32e38b078a85c34eb315 to your computer and use it in GitHub Desktop.
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.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