· 7 years ago · Nov 24, 2018, 11:28 PM
1import org.bonilla.crypto.AES;
2import org.bonilla.crypto.MD5;
3import org.bonilla.manager.JEncryptorManager;
4import org.bonilla.manager.JEncryptorType;
5
6import java.io.File;
7
8public class Main {
9 public static void main(String[] args) {
10 // JEncryptorData & Message
11 File data = new File("src/JEncryptorData.json");
12 String message = "JEncryptor by Pablo";
13
14
15 // AES
16 // with file
17 // JEncryptorManager jem = new JEncryptorManager(JEncryptorType.AES, data);
18 // AES crypto = (AES) jem.getInstance();
19 //String encrypted = crypto.encrypt(message);
20
21 // no file
22 JEncryptorManager jem = new JEncryptorManager(JEncryptorType.AES);
23 AES crypto = (AES) jem.getInstance();
24 String secretKey = "770A8A65DA156D24EE2A093277530142";
25 String initVector = "b34afd4a9d7fc1e9";
26 String encrypted = crypto.encrypt(message, secretKey, initVector);
27
28
29 // MD5
30 // with file
31 // JEncryptorManager jem = new JEncryptorManager(JEncryptorType.MD5, data);
32 // MD5 crypto = (MD5) jem.getInstance();
33 // String encrypted = crypto.encrypt(message);
34
35 // no file
36 // JEncryptorManager jem = new JEncryptorManager(JEncryptorType.MD5);
37 // MD5 crypto = (MD5) jem.getInstance();
38 // String salt = "0fb09c95";
39 // String encrypted = crypto.encrypt(message, salt);
40
41
42
43 // Encrypted output
44 System.out.println("Encrypted: " + encrypted);
45
46
47
48 // AES output (with file)
49 // String decrypted = crypto.decrypt(encrypted);
50 // System.out.println("Decrypted: " + decrypted);
51
52 // AES output (no file)
53 String decrypted = crypto.decrypt(encrypted, secretKey, initVector);
54 System.out.println("Decrypted: " + decrypted);
55
56
57
58
59
60 // MD5 ouput (with file)
61 // String hash = "eb4af72f1334abb33cddbdadf3d48295";
62 // boolean isEqual = crypto.compareHash(message, hash);
63 // System.out.println("Is hash equal: " + isEqual);
64
65 // MD5 output (no file)
66 // String hash = "eb4af72f1334abb33cddbdadf3d48295";
67 // boolean isEqual = crypto.compareHash(message, salt, hash);
68 // System.out.println("Is hash equal: " + isEqual);
69
70
71 }
72}