package org.jboss.test;
import org.jboss.security.Util;
public class PasswordHasher
{
static String usage = "Usage: [hashAlgorithm [hashEncoding [hashCharset]]] password";
public static void main(String[] args)
{
String hashAlgorithm = "MD5";
String hashEncoding = "base64";
String hashCharset = null;
String password = null;
if( args.length == 0 || args[0].startsWith("-h") )
throw new IllegalStateException(usage);
switch( args.length )
{
case 4:
hashAlgorithm = args[0];
hashEncoding = args[1];
hashCharset = args[2];
password = args[3];
break;
case 3:
hashAlgorithm = args[0];
hashEncoding = args[1];
password = args[2];
break;
case 2:
hashAlgorithm = args[0];
password = args[1];
break;
case 1:
password = args[0];
break;
}
String passwordHash = Util.createPasswordHash(hashAlgorithm, hashEncoding,
hashCharset, null, password);
System.out.println("passwordHash = "+passwordHash);
}
}