首页 > 学院 > 开发设计 > 正文

MD5加密

2019-11-06 09:54:26
字体:
来源:转载
供稿:网友

public class md5Util {	PRivate static final char hexDigits[] = { '0', '1', '2', '3', '4', '5',			'6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };	public static String getMD5(String inStr) {		byte[] inStrBytes = inStr.getBytes();		try {			MessageDigest MD = MessageDigest.getInstance("MD5");			MD.update(inStrBytes);			byte[] mdByte = MD.digest();			char[] str = new char[mdByte.length * 2];			int k = 0;			for (int i = 0; i < mdByte.length; i++) {				byte temp = mdByte[i];				str[k++] = hexDigits[temp >>> 4 & 0xf];				str[k++] = hexDigits[temp & 0xf];			}			return new String(str);		} catch (NoSuchAlgorithmException e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		return null;	}}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表