01: package com.jat.util.security;
02:
03: import java.security.MessageDigest;
04: import java.security.NoSuchAlgorithmException;
05: import com.jat.core.log.LogManager;
06:
07: /**
08: * <p>Title: JAT</p>
09: * <p>Description: </p>
10: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
11: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
12: * @author stf
13: * @version 1.0
14: * @since 1.2
15: */
16:
17: public class SecurityUtil {
18:
19: public SecurityUtil() {
20: }
21:
22: public static String encrypt(String data, String algorithm)
23: throws NoSuchAlgorithmException {
24: if (algorithm == null || algorithm.equals(""))
25: return data;
26: MessageDigest md = MessageDigest.getInstance(algorithm);
27: md.update(data.getBytes());
28: byte[] dig = md.digest();
29: String ret = "";
30: for (int i = 0; i < dig.length; i++)
31: ret += dig[i];
32: LogManager
33: .sendDebug("com.jat.business.authentication.RegistredUser::encrypt: encrypt: "
34: + ret);
35: return new String(ret);
36: }
37:
38: }
|