MD5加密

阅读更多
package com.exl;
import java.security.MessageDigest;
/**
 * MD5加密
 * @author yuqiang.cui
 *
 */
public class MD5_test {
	/**
	 * MD5加密
	 * @param str 需要加密字符串
	 * @return 加密后的字符串
	 */
	public static String encrypt(String str) {
		StringBuffer sb = new StringBuffer(32);
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] array = md.digest(str.getBytes("utf-8"));
			for (int i = 0; i < array.length; i++) {
				sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
			}
		} catch (Exception e) {
			return null;
		}
		return sb.toString();
	}
}

 

你可能感兴趣的:(Security,AES,3DES,RSA)