01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test;
23:
24: import org.jboss.security.Util;
25:
26: /** A utility program for generating password hashes given the hashAlgorithm,
27: hashEncoding, and hashCharset options used by the UsernamePasswordLoginModule.
28: The command line usage is:
29: PasswordHasher [hashAlgorithm [hashEncoding [hashCharset]]] password
30:
31: @author Scott.Stark@jboss.org
32: @version $Revision: 37390 $
33: */
34: public class PasswordHasher {
35: static String usage = "Usage: [hashAlgorithm [hashEncoding [hashCharset]]] password";
36:
37: /** @param args the command line arguments
38: *Usage: [hashAlgorithm [hashEncoding [hashCharset]]] password
39: */
40: public static void main(String[] args) {
41: String hashAlgorithm = "MD5";
42: String hashEncoding = "base64";
43: String hashCharset = null;
44: String password = null;
45: if (args.length == 0 || args[0].startsWith("-h"))
46: throw new IllegalStateException(usage);
47: switch (args.length) {
48: case 4:
49: hashAlgorithm = args[0];
50: hashEncoding = args[1];
51: hashCharset = args[2];
52: password = args[3];
53: break;
54: case 3:
55: hashAlgorithm = args[0];
56: hashEncoding = args[1];
57: password = args[2];
58: break;
59: case 2:
60: hashAlgorithm = args[0];
61: password = args[1];
62: break;
63: case 1:
64: password = args[0];
65: break;
66: }
67: String passwordHash = Util.createPasswordHash(hashAlgorithm,
68: hashEncoding, hashCharset, null, password);
69: System.out.println("passwordHash = " + passwordHash);
70: }
71:
72: }
|