public static String encodePassword(String password,String algorithm){
  byte[] unencodedPassword=password.getBytes();
  MessageDigest md=null;
  try {
    md=MessageDigest.getInstance(algorithm);
  }
 catch (  Exception e) {
    log.error("Exception: " + e);
    return password;
  }
  md.reset();
  md.update(unencodedPassword);
  byte[] encodedPassword=md.digest();
  StringBuffer buf=new StringBuffer();
  for (  byte anEncodedPassword : encodedPassword) {
    if ((anEncodedPassword & 0xff) < 0x10) {
      buf.append("0");
    }
    buf.append(Long.toString(anEncodedPassword & 0xff,16));
  }
  return buf.toString();
}

public static String encodePassword ( String password , String algorithm ) { byte [ ] unencodedPassword = password . getBytes ( ) ; MessageDigest md = null ; try { md = MessageDigest . getInstance ( algorithm ) ; } catch ( Exception e ) { log . error ( "Exception: " + e ) ; return password ; } md . reset ( ) ; md . update ( unencodedPassword ) ; byte [ ] encodedPassword = md . digest ( ) ; StringBuffer buf = new StringBuffer ( ) ; for ( byte anEncodedPassword : encodedPassword ) { if ( ( anEncodedPassword & 0xff ) < 0x10 ) { buf . append ( "0" ) ; } buf . append ( Long . toString ( anEncodedPassword & 0xff , 16 ) ) ; } return buf . toString ( ) ; }
encode a string using algorithm specified in web . xml and return the resulting encrypted password . if exception , the plain credentials string is returned
