-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSHA512.java
More file actions
30 lines (29 loc) · 1.02 KB
/
Copy pathSHA512.java
File metadata and controls
30 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Scanner;
public class SHA512 {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
System.out.println("Enter the value you want to find the hash value for");
String message=scan.nextLine();
String hash=findHash(message);
System.out.println("The corresponding hash value is: "+hash);
}
public static String findHash(String Message){
try {
MessageDigest messdig = MessageDigest.getInstance("SHA-512");
byte[] bytearr= messdig.digest(Message.getBytes(StandardCharsets.UTF_8));
BigInteger integer=new BigInteger(1,bytearr);
String hash=integer.toString(16);
while(hash.length()<64){
hash="0"+hash;
}
return hash;
}
catch (Exception e){
System.out.println(e);
}
return null;
}
}