Index: lams_common/src/java/org/lamsfoundation/lams/util/HashUtil.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/util/HashUtil.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/util/HashUtil.java (revision a3babeb2dac0e7a334f0e7507607817c95c2ff07) @@ -0,0 +1,53 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +package org.lamsfoundation.lams.util; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.commons.codec.binary.Hex; + +/** + * @version + * + *

+ * View Source + *

+ * + * @author Fei Yang + * + * Created at 16:25:56 on 20/06/2006 + */ +public class HashUtil { + + public static String sha1(String plaintext) throws NoSuchAlgorithmException{ + MessageDigest md = MessageDigest.getInstance("SHA1"); + return new String(Hex.encodeHex(md.digest(plaintext.getBytes()))); + } + + public static String md5(String plaintext) throws NoSuchAlgorithmException{ + MessageDigest md = MessageDigest.getInstance("MD5"); + return new String(Hex.encodeHex(md.digest(plaintext.getBytes()))); + } + +}