KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > util > security > EncryptTool


1 package de.webman.util.security;
2
3 import java.io.BufferedReader JavaDoc;
4 import java.io.InputStreamReader JavaDoc;
5 import java.io.IOException JavaDoc;
6
7 /**
8  * This is small utility application, used to generate encrypted passwords
9  * 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 {
17     /* $Id: EncryptTool.java,v 1.2 2002/04/12 13:55:58 gregor Exp $ */
18
19     /**
20      * prints a source password and it's encrypted form
21      * @param str the string to print
22      **/

23     public static void showLine(String JavaDoc str) {
24         System.out.println(str + " -> " + EncryptUtil.encrypt(str));
25     }
26
27     /**
28      * show the usage
29      **/

30     private static void showUsage() {
31         System.out.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.println("wm-encrypt encrypt passwords using MD5 and printing them ");
37         System.out.println("base64 encoded to stdout. If no passwords are given on the");
38         System.out.println("command line, the tools requests them interactively from");
39         System.out.println("stdin. Please note, that encrypted passwords never contains");
40         System.out.println("any whitespace. You may past and copy the passwords into");
41         System.out.println("the ldap.xml file used by the synchronization mechanism.");
42         System.out.println("");
43     }
44     
45     /**
46      * the main function of this app
47      * @param args guess what
48      **/

49     public static void main(String JavaDoc[] args) {
50
51         if (args.length == 0) {
52             try {
53                 BufferedReader JavaDoc brd = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(System.in));
54                 boolean done = false;
55                 
56                 while (!done) {
57                     System.out.print("* ");
58                     System.out.flush();
59                     String JavaDoc line = brd.readLine();
60
61                     if (line == null)
62                         done = true;
63                     else {
64                         showLine(line.trim());
65                     }
66                 }
67                 
68                 brd.close();
69             }
70             catch (IOException JavaDoc ioe) {
71                 System.err.println(ioe);
72                 System.exit(-1);
73             }
74         }
75         else {
76             for (int l = 0; l < args.length; l++) {
77                 if ("--help".equals(args[l]) || "-h".equals(args[l])) {
78                     showUsage();
79                     System.exit(0);
80                 }
81                 else
82                     showLine(args[l]);
83             }
84         }
85     }
86 }
87
Popular Tags