-
Notifications
You must be signed in to change notification settings - Fork 1
/
MD5Encryption.java
57 lines (47 loc) · 1.75 KB
/
MD5Encryption.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Here comes the text of your license
* Each line should be prefixed with *
*/
package SystemSecurity;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.swing.JOptionPane;
/**
*
* @author samuel owino
*/
public class MD5Encryption {
private static String cipherText;
public static void main(String[] args) {
String input = JOptionPane.showInputDialog(null,"Enter password");
if(getCiphertext(input).equals(getCiphertext("emma"))){
JOptionPane.showMessageDialog(null,"plus");
}else {
JOptionPane.showMessageDialog(null,"negative");
}
}
public static String getCiphertext(String password){
try {
//Create a messageDigest instance
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
//Add a password to digest
messageDigest.update(password.getBytes());
//Get the hash bytes
byte[] bytes = messageDigest.digest();
//this byte[] has bytes in dcimal format
//Convert to hexadecimal format
StringBuilder stringBuilder = new StringBuilder();
for(int i=0;i<bytes.length;i++){
stringBuilder.append(Integer.toString((bytes[i] & 0xFF)+0x100,16).substring(1));
}
//Get complete hashed password in hex format
cipherText = stringBuilder.toString();
System.err.println(cipherText);
} catch (NoSuchAlgorithmException e) {
}
return cipherText;
}
protected static String getDecryptedPassword(){
return "";
}
}