01: package de.webman.util.security;
02:
03: import java.io.BufferedReader;
04: import java.io.InputStreamReader;
05: import java.io.IOException;
06:
07: /**
08: * This is small utility application, used to generate encrypted passwords
09: * as used by the ldap/sync mechanism.
10: *
11: * @author <a href="mailto:gregor@webman.de">Gregor Klinke</a>
12: * @version $Revision: 1.2 $
13: **/
14:
15: public class EncryptTool {
16: /* $Id: EncryptTool.java,v 1.2 2002/04/12 13:55:58 gregor Exp $ */
17:
18: /**
19: * prints a source password and it's encrypted form
20: * @param str the string to print
21: **/
22: public static void showLine(String str) {
23: System.out.println(str + " -> " + EncryptUtil.encrypt(str));
24: }
25:
26: /**
27: * show the usage
28: **/
29: private static void showUsage() {
30: System.out
31: .println("java de.webman.util.security.EncryptTool [options] [PASSWORD ...]");
32: System.out.println("");
33: System.out.println("Options:");
34: System.out.println(" --help this help");
35: System.out.println("");
36: System.out
37: .println("wm-encrypt encrypt passwords using MD5 and printing them ");
38: System.out
39: .println("base64 encoded to stdout. If no passwords are given on the");
40: System.out
41: .println("command line, the tools requests them interactively from");
42: System.out
43: .println("stdin. Please note, that encrypted passwords never contains");
44: System.out
45: .println("any whitespace. You may past and copy the passwords into");
46: System.out
47: .println("the ldap.xml file used by the synchronization mechanism.");
48: System.out.println("");
49: }
50:
51: /**
52: * the main function of this app
53: * @param args guess what
54: **/
55: public static void main(String[] args) {
56:
57: if (args.length == 0) {
58: try {
59: BufferedReader brd = new BufferedReader(
60: new InputStreamReader(System.in));
61: boolean done = false;
62:
63: while (!done) {
64: System.out.print("* ");
65: System.out.flush();
66: String line = brd.readLine();
67:
68: if (line == null)
69: done = true;
70: else {
71: showLine(line.trim());
72: }
73: }
74:
75: brd.close();
76: } catch (IOException ioe) {
77: System.err.println(ioe);
78: System.exit(-1);
79: }
80: } else {
81: for (int l = 0; l < args.length; l++) {
82: if ("--help".equals(args[l]) || "-h".equals(args[l])) {
83: showUsage();
84: System.exit(0);
85: } else
86: showLine(args[l]);
87: }
88: }
89: }
90: }
|