-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathJavaSHA-256.java
More file actions
24 lines (20 loc) · 706 Bytes
/
Copy pathJavaSHA-256.java
File metadata and controls
24 lines (20 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.security.MessageDigest;
public class Solution {
public static void main(String[] args) throws Exception{
Scanner sc=new Scanner(System.in);
String text=sc.nextLine();
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(text.getBytes());
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));
}
System.out.println(sb.toString());
}
}