forked from siddharth-prodapt/encrypt-password
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncryptPassword.java
43 lines (31 loc) · 1.2 KB
/
EncryptPassword.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
// Encryption and Decryption in Java
import java.security.MessageDigest;
import java.util.Base64;
import java.util.Arrays;
import java.io.*;
import java.util.*;
class EncryptPassword{
public static void main(String[] args) {
// String text = "hello"; //69609650
// System.out.println(text.hashCode());
try{
String msg = "asdf";
Scanner sc = new Scanner(System.in);
// msg = sc.nextLine();
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(msg.getBytes());
byte[] digest = md.digest();
// System.out.println("Digest: "+digest);
// System.out.println("-->"+Arrays.toString(digest));
StringBuffer hexString = new StringBuffer();
hexString.append(Integer.toHexString(0xFF & digest[0]));
// for(int i = 0; i<digest.length; i++){
// hexString.append(Integer.toHexString(0xFF & digest[i]));
// }
System.out.println("Hex Format: " + hexString.toString());
}
catch(Exception e){
System.out.println("Exception: "+e);
}
}
}