xiaoqingge 2014-05-05
最近在对一个现有的系统进行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; }
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh