using System;
using System.IO;
using System.Security.Cryptography;
namespace createAuthKey
{
class MainClass
{
public static void Main(string[] args)
{
String key = "888888";
String domain = "http://osscdn.pier39.cn";
String urlPath = "/test.html";
String timeStamp = UnixTimeStamp(30);
String auth_md5 = GetMd5(urlPath + "-" + timeStamp + "-0-0-" + key);
String auth_key = timeStamp + "-0-0-" + auth_md5;
String url = domain + urlPath + "?auth_key=" + auth_key;
Console.WriteLine(url);
}
public static String UnixTimeStamp(long time){
double seconds = (DateTime.Now.AddMinutes(time) - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds;
return seconds.ToString("#");
}
public static String GetMd5(String msg){
String str = "";
byte[] data = System.Text.Encoding.GetEncoding("utf-8").GetBytes(msg);
MD5 mD5 = new MD5CryptoServiceProvider();
byte[] bytes = mD5.ComputeHash(data);
for (int i = 0; i < bytes.Length;i++){
str += bytes[i].ToString("x2");
}
return str;
}
}
}