1 Reply Latest reply on Oct 17, 2007 1:33 PM by Thomas Bauer

    How to decode hash password?

    Eugene Kisly Newbie

      Seamspace example:

      package org.teamdev.librarian.user;
      
      import org.apache.commons.codec.binary.Hex;
      import org.jboss.seam.Component;
      import org.jboss.seam.annotations.Name;
      
      import java.security.MessageDigest;
      
      @Name("hash")
      public class Hash {
       String hashFunction = "MD5";
       String charset = "UTF-8";
      
       public String hash(String password) {
       try {
       MessageDigest md = MessageDigest.getInstance(hashFunction);
       md.update(password.getBytes(charset));
       byte[] raw = md.digest();
       return new String(Hex.encodeHex(raw));
       }
       catch (Exception e) {
       throw new RuntimeException(e);
       }
       }
      
       public String getCharset() {
       return charset;
       }
      
       public void setCharset(String charset) {
       this.charset = charset;
       }
      
       public String getHashFunction() {
       return hashFunction;
       }
      
       public void setHashFunction(String hashFunction) {
       this.hashFunction = hashFunction;
       }
      
       public static Hash instance() {
       return (Hash) Component.getInstance(Hash.class);
       }
      }


      How to decode (unhash) password?

      public String unHash(String hashedPassword) {
       try {
       MessageDigest md = MessageDigest.getInstance(hashFunction);
       md.update(hashedPassword.getBytes(charset));
       char[] raw = md.digest().toString().toCharArray();
       return new String(Hex.decodeHex(raw));
       }
       catch (Exception e) {
       throw new RuntimeException(e);
       }
       }


      Don't work =(