md5加密代码

package com.gyarmy.test;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {
	
	public static String md5(String value){
		
		String md5Str = "";
		
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			byte[] myValue = value.getBytes();
			byte[] md5Value = md5.digest(myValue);
			
			//输出md5的值
			for(byte b : md5Value){
				//System.out.print(Integer.toHexString(b)+" - ");
				int d = b & 0xff;
				String hexString = Integer.toHexString(d);
				if(hexString.length() == 1){
					hexString = "0" + hexString; 
				}
				//md5String.append(hexString);
				md5Str+=hexString;
			}
			
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return md5Str+"";
	}
	
}

原文链接: md5加密代码 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( http://gyarmy.com/post-160.html )

发表评论

0则评论给“md5加密代码”