最近在对一个现有的系统进行C#改造,该系统以前是用PHP做的,后台的管理员登陆用的是MD5加密算法。在PHP中,要对一个字符串进行MD5加密非常简单,一行代码即可:
复制代码 代码如下:
md5("Something you want to encrypt.")
复制代码 代码如下:
public static string MD5(string stringToHash)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(stringToHash, "md5");
}
复制代码 代码如下:
public static string MD5ForPHP(string stringToHash)
{
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] emailBytes = Encoding.UTF8.GetBytes(stringToHash.ToLower());
byte[] hashedEmailBytes = md5.ComputeHash(emailBytes);
StringBuilder sb = new StringBuilder();
foreach (var b in hashedEmailBytes)
{
sb.Append(b.ToString("x2").ToLower());
}
return sb.ToString();
}
复制代码 代码如下:
public static string MD5ForPHP(this String, string stringToHash)
{
// Your code here.
}
复制代码 代码如下:
public static DateTime UnixTimeStampToDateTime(long unixTimeStamp)
{
// Unix timestamp is seconds past epoch
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
return dtDateTime.AddSeconds(unixTimeStamp);
}
public static long DateTimeToUnixTimeStamp(DateTime datetime)
{
TimeSpan span = (datetime - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));
return (long)span.TotalSeconds;
}
新闻热点
疑难解答
图片精选