1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.miloss.fgsms.common;
21
22 import java.sql.Connection;
23 import java.sql.PreparedStatement;
24
25
26
27
28
29
30
31
32 public class Main {
33
34 public static void main(String[] args) {
35 if (args==null || args.length == 0) {
36 PrintUsage();
37 } else if (args.length == 1 && args[0].equalsIgnoreCase("en")) {
38
39 try {
40 System.out.print("Enter password: ");
41 String s = new String(System.console().readPassword());
42 System.out.print("Enter password to confirm: ");
43 String s2 = new String(System.console().readPassword());
44 if (s.equalsIgnoreCase(s2)) {
45
46 System.out.println("Cipher Text: " + AES.EN(s));
47 } else {
48 System.out.println("Passwords do not match");
49 }
50 } catch (Exception ex) {
51 System.out.println("Error caught encrypting string. This usually indicates that you have not yet installed the unlimited strenth Java Crypto Extensions. This can be downloaded at http://www.oracle.com/technetwork/java/javase/downloads/index.html " + ex.getMessage());
52 ex.printStackTrace();
53 }
54 } else if (args.length >= 1 && args[0].equalsIgnoreCase("gen")) {
55
56 short keysize = 256;
57 if (args.length > 1) {
58 try {
59 keysize = Short.parseShort(args[1]);
60 } catch (Exception ex) {
61 ex.printStackTrace();
62 }
63 }
64 String key = AES.GEN(keysize);
65 if (key != null) {
66 System.out.println(key);
67 } else {
68 System.out.println("Unable to generate key. This usually indicates that you have not yet installed the unlimited strenth Java Crypto Extensions. This can be downloaded at http://www.oracle.com/technetwork/java/javase/downloads/index.html ");
69 }
70
71 } else {
72 PrintUsage();
73 }
74
75 }
76
77 private static void PrintUsage() {
78 System.out.println("Usage ....");
79 System.out.println("java -jar fgsms.Common.jar en\t\tThis will encrypt a password using AES.");
80 System.out.println("java -jar fgsms.Common.jar gen\t\tThis will generate a new 256 bit encryption key.");
81 System.out.println("java -jar fgsms.Common.jar gen (size)\t\tThis will generate a new (size) bit encryption key.");
82
83
84 }
85
86
87
88
89
90
91
92
93
94
95 }