-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSHA1LIB.java
32 lines (28 loc) · 1.09 KB
/
SHA1LIB.java
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
31
32
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
public class SHA1LIB {
public static String encryptThisString(String input) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger no = new BigInteger(1, messageDigest);
String hashtext = no.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
public static void main(String args[]) throws NoSuchAlgorithmException {
System.out.println("----SHA-1----");
System.out.println("Insert a word a phrase to be hashed");
Scanner sc = new Scanner(System.in);
String word = sc.nextLine();
System.out.println("Plain Text: " + word);
System.out.println("Encrypted Text: " + encryptThisString(word));
}
}