Java中用MD5保存用户密码 简单实例

/**
	 * 生成MD5简单方法
	 * @param str
	 * @return
	 */
	public StringBuilder getMD5(String str){
		byte [] buf=str.getBytes();
		MessageDigest md5;
		StringBuilder sb=new StringBuilder();
		try {
			md5 = MessageDigest.getInstance("MD5");
			md5.update(buf);
			byte [] tmp=md5.digest();
			for (byte b:tmp) {
				sb.append(Integer.toHexString(b&0xff));
			}
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sb;
	}

 

你可能感兴趣的:(java)