首页>代码>JSP网站开发聚宝网上商城源代码下载>/聚宝商城/10/sl/01/src/com/alipay/util/Md5Encrypt.java
��/**

 * Alipay.com Inc. Copyright (c) 2004-2005 All Rights Reserved.

 * 

 * <p>

 * Created on 2005-7-9

 * </p>

 */

package com.alipay.util;



import java.io.UnsupportedEncodingException;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;



/**

 * MD5R�[�{�l�

 */

public class Md5Encrypt {

	/**

	 * Used building output as Hex

	 */

	private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6',

			'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };



	/**

	 * [�[W{&N2�ۈLMD5R�[�

	 * 

	 * @param text

	 *            fe�

	 * 

	 * @return [�e�

	 */

	public static String md5(String text) {

		MessageDigest msgDigest = null;



		try {

			msgDigest = MessageDigest.getInstance("MD5");

		} catch (NoSuchAlgorithmException e) {

			throw new IllegalStateException(

					"System doesn't support MD5 algorithm.");

		}



		try {

			msgDigest.update(text.getBytes("GBK"));



		} catch (UnsupportedEncodingException e) {



			throw new IllegalStateException(

					"System doesn't support your  EncodingException.");



		}



		byte[] bytes = msgDigest.digest();



		String md5Str = new String(encodeHex(bytes));



		return md5Str;

	}



	public static char[] encodeHex(byte[] data) {



		int l = data.length;



		char[] out = new char[l << 1];



		// two characters form the hex value.

		for (int i = 0, j = 0; i < l; i++) {

			out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];

			out[j++] = DIGITS[0x0F & data[i]];

		}



		return out;

	}



}
最近下载更多
zj20020510  LV5 2023年9月18日
寒江雪2017  LV10 2023年8月2日
sunrandong  LV4 2023年6月9日
17693282606  LV12 2022年7月10日
shuangerduo  LV9 2022年6月26日
2998919365  LV5 2022年5月27日
georgejin  LV9 2022年5月13日
不停的奔跑  LV20 2022年3月20日
wouldbb  LV6 2021年12月18日
啊凯a  LV2 2021年12月9日
最近浏览更多
lt6666 1月1日
暂无贡献等级
ma406805131  LV19 2024年12月18日
微信网友_7290996505972736  LV4 2024年12月11日
chinajy  LV2 2024年12月8日
微信网友_7222576034680832  LV2 2024年10月23日
凌风丶  LV1 2024年9月19日
Ruler113 2024年9月10日
暂无贡献等级
kuyedie  LV1 2024年6月23日
hlFDGd  LV1 2024年6月11日
孤独的根号三  LV1 2024年5月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友