/**
 * Cobub Razor
 * <p>
 * An open source analytics android sdk for mobile applications
 *
 * @package Cobub Razor
 * @author WBTECH Dev Team
 * @copyright Copyright (c) 2011 - 2012, NanJing Western Bridge Co.,Ltd.
 * @license http://www.cobub.com/products/cobub-razor/license
 * @link http://www.cobub.com/products/cobub-razor/
 * @filesource
 * @since Version 0.1
 */
package com.oo.seex.oo_statistics_lib.utils;

import android.content.Context;

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

public class MD5Utility {
    /**
     * 特有防伪标示符
     *
     * @param time
     * @param context
     * @return
     */
    public static String getSecrect_key(String time, Context context) {
        return md5Appkey(CommonUtil.getAppKey(context) + time);
//        return "08f93cc52fafd6d49aa450acf577375a";
//        + CommonUtil.getMasterKey(context)
    }

    /**
     * 对字符串进行加密
     *
     * @param str
     * @return
     */
    public static String md5Appkey(String str) {
    /*str   To encrypt a string
     * parmboolean  string's length，true false
	 * **/
        try {
            MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
            localMessageDigest.update(str.getBytes());
            byte[] arrayOfByte = localMessageDigest.digest();

            StringBuffer localStringBuffer = new StringBuffer();
            for (int i = 0; i < arrayOfByte.length; i++) {
                if (Integer.toHexString(0xFF & arrayOfByte[i]).length() == 1)
                    localStringBuffer.append("0").append(Integer.toHexString(0xFF & arrayOfByte[i]));
                else
                    localStringBuffer.append(Integer.toHexString(0xFF & arrayOfByte[i]));
            }
            return localStringBuffer.toString();
        } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
            CommonUtil.printLog("MD5Utility", "getMD5 error");
            CommonUtil.printLog(localNoSuchAlgorithmException);
        }
        return "";
    }

}
