Created
February 17, 2018 06:15
-
-
Save computingfreak/a7d991d1d5de95f47ba2f12e13d611d3 to your computer and use it in GitHub Desktop.
SHA-256
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.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
import java.security.*; | |
public class sha256 { | |
public static void main(String[] args) throws Exception{ | |
Scanner scr = new Scanner(System.in); | |
String str = scr.next(); | |
byte[] bytesOfMessage = str.getBytes(); | |
MessageDigest md = MessageDigest.getInstance("SHA-256"); | |
md.update(str.getBytes(),0,str.length()); | |
System.out.println(toHex(md.digest())); | |
} | |
private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray(); | |
public static String toHex(byte[] data) { | |
char[] chars = new char[data.length * 2]; | |
for (int i = 0; i < data.length; i++) { | |
chars[i * 2] = HEX_DIGITS[(data[i] >> 4) & 0xf]; | |
chars[i * 2 + 1] = HEX_DIGITS[data[i] & 0xf]; | |
} | |
return new String(chars); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment