using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace BLWWSCore
{
    public class Common
    {
        public static string MD5Encrypt(string str)
        {
            MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            byte[] hashedDataBytes;
            hashedDataBytes = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str));
            StringBuilder tmp = new StringBuilder();
            foreach (byte i in hashedDataBytes)
            {
                tmp.Append(i.ToString("x2"));
            }
            return tmp.ToString();
        }
        public static long GetCurrentTimeStamp(DateTime dt)
        {
            TimeSpan ts = dt - new DateTime(1970, 1, 1, 8, 0, 0, DateTimeKind.Local);
            long current_timestamp = Convert.ToInt64(ts.TotalSeconds);
            return current_timestamp;
        }
        public static DateTime GetCurrentDateTime(long timestampseconds)
        {
            DateTime epoch = new DateTime(1970, 1, 1, 8, 0, 0, DateTimeKind.Local);
            DateTime utcTime = epoch.AddSeconds(timestampseconds);
            return utcTime;
        }
    }
}