KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportmanager > PasswordEncryptor


1 package com.calipso.reportgenerator.reportmanager;
2
3 import com.calipso.reportgenerator.common.InfoException;
4 import com.calipso.reportgenerator.common.LanguageTraslator;
5
6 import java.security.MessageDigest JavaDoc;
7
8 /**
9  * Encriptador
10  */

11
12 public class PasswordEncryptor {
13
14   /**
15    * Devuelve el hash correspondiente a una contrasena dada.
16    * @param password
17    * @return
18    */

19   public static String JavaDoc getEncryptedPassword(String JavaDoc password) throws InfoException {
20     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
21     try {
22       byte [] encrypt = password.getBytes("UTF-8");
23       MessageDigest JavaDoc md = MessageDigest.getInstance("SHA");
24       md.update(encrypt);
25       byte [] hashedPasswd = md.digest();
26       for(int i = 0 ; i < hashedPasswd.length ; i++) {
27         buffer.append(Byte.toString(hashedPasswd [i]));
28       }
29     } catch(Exception JavaDoc e) {
30       throw new InfoException(LanguageTraslator.traslate("474"),e);
31     }
32     return buffer.toString();
33   }
34 }
35
Popular Tags