package com.bcxin.file;

import com.bcxin.file.model.FileLog;
import sun.misc.BASE64Encoder;

import javax.swing.*;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * 采用MD5加密解密
 * 
 * @author tfq
 * @datetime 2011-10-13
 */
public class MD5Util {

	/*** @param str 待加密字符串
	 * @return 16进制加密字符串
	 */
	public static String encryptToMD5(String str) {
		// 加密后的16进制字符串
		String hexStr = "";
		try {
			// 此 MessageDigest 类为应用程序提供信息摘要算法的功能
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			// 转换为MD5码
			byte[] digest = md5.digest(str.getBytes("utf-8"));
			hexStr = toHexString(digest);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hexStr;
	}
	private static String toHexString(byte[] md5Bytes){
		StringBuffer hexValue = new StringBuffer();
		for (int i = 0; i < md5Bytes.length; i++) {
			int val = ((int) md5Bytes[i]) & 0xff;
			if (val < 16)
				hexValue.append("0");
			hexValue.append(Integer.toHexString(val));
		}
		return hexValue.toString();
	}

	public static void main(String[] args) {
		DataBaseUtil dataBaseUtil = null;
		try {
			dataBaseUtil = new DataBaseUtil();
			List<FileLog> logList = null;
			List<FileLog> dbLogs = dataBaseUtil.readData2(logList);
			//logList.removeAll(dbLogs);
			System.out.println(dbLogs);
		}catch (Exception e){

		}
	}
}
