1 7 package org.jboss.test; 8 9 import org.jboss.security.Util; 10 11 19 public class PasswordHasher 20 { 21 static String usage = "Usage: [hashAlgorithm [hashEncoding [hashCharset]]] password"; 22 23 26 public static void main(String [] args) 27 { 28 String hashAlgorithm = "MD5"; 29 String hashEncoding = "base64"; 30 String hashCharset = null; 31 String password = null; 32 if( args.length == 0 || args[0].startsWith("-h") ) 33 throw new IllegalStateException (usage); 34 switch( args.length ) 35 { 36 case 4: 37 hashAlgorithm = args[0]; 38 hashEncoding = args[1]; 39 hashCharset = args[2]; 40 password = args[3]; 41 break; 42 case 3: 43 hashAlgorithm = args[0]; 44 hashEncoding = args[1]; 45 password = args[2]; 46 break; 47 case 2: 48 hashAlgorithm = args[0]; 49 password = args[1]; 50 break; 51 case 1: 52 password = args[0]; 53 break; 54 } 55 String passwordHash = Util.createPasswordHash(hashAlgorithm, hashEncoding, 56 hashCharset, null, password); 57 System.out.println("passwordHash = "+passwordHash); 58 } 59 60 } 61 | Popular Tags |