Update of /cvsroot/struts/struts-resume/src/common/org/appfuse/common/util
In directory sc8-pr-cvs1:/tmp/cvs-serv28341
Added Files:
BaseUtil.java StringUtil.java
Log Message:
--- NEW FILE: BaseUtil.java ---
package org.appfuse.common.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* BaseUtil is used as a parent class for all other classes in the
* common.utils package.
* @author Matt Raible (matt@raibledesigns)
*/
public class BaseUtil {
/**
* The <code>Log</code> instance for this class.
*/
protected Log log = LogFactory.getLog(BaseUtil.class);
}
--- NEW FILE: StringUtil.java ---
package org.appfuse.common.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.security.MessageDigest;
/**
* String Utility Class This is used to encode passwords programmatically
*
* @author Matt Raible
* @version $Revision: 1.1 $ $Date: 2003/01/08 05:51:57 $
*/
public class StringUtil extends BaseUtil
{
//~ Static fields/initializers =============================================
/** The <code>Log</code> instance for this class. */
private static Log log = LogFactory.getLog(StringUtil.class);
//~ Methods ================================================================
/**
* Encode a string using algorithm specified in web.xml and return the
* resulting encrypted password. If exception, the plain credentials
* string is returned
*
* @param password Password or other credentials to use in authenticating
* this username
* @param algorithm Algorithm used to do the digest
*
* @return DOCUMENT ME!
*/
public static String encodePassword(String password, String algorithm)
{
byte[] unencodedPassword = password.getBytes();
MessageDigest md = null;
try {
// first create an instance, given the provider
md = MessageDigest.getInstance(algorithm);
} catch (Exception e) {
log.error("Exception: " + e);
return password;
}
md.reset();
// call the update method one or more times
// (useful when you don't know the size of your data, eg. stream)
md.update(unencodedPassword);
// now calculate the hash
byte[] encodedPassword = md.digest();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < encodedPassword.length; i++) {
if (((int) encodedPassword[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString((int) encodedPassword[i] & 0xff, 16));
}
return buf.toString();
}
}
|