1.MD5函数
public static string MD5(string str)
{
byte[] b = Encoding.UTF8.GetBytes(str);
b = new MD5CryptoServiceProvider().ComputeHash(b);
string ret = "";
for (int i = 0; i < b.Length; i++)
{
ret += b[i].ToString("x").PadLeft(2, ‘0‘);
}
return ret;
}
2.SHA256函数
public static string SHA256(string str)
{
byte[] SHA256Data = Encoding.UTF8.GetBytes(str);
SHA256Managed Sha256 = new SHA256Managed();
byte[] Result = Sha256.ComputeHash(SHA256Data);
return Convert.ToBase64String(Result); //返回长度为44字节的字符串
}
3.将指定日期转换成yyyy年MM月dd日形式
public static string SubLastThreeZero(Object strNumber)
{
if (strNumber != null && !string.IsNullOrEmpty(strNumber.ToString().Trim()))
{
string[] Nums = strNumber.ToString().Trim().Split(‘.‘);
if (Nums.Length == 2)
{
Byte[] NumBytes = Encoding.ASCII.GetBytes(Nums[1]);
Char[] NumChars = Encoding.ASCII.GetChars(NumBytes);
ArrayList arr = new ArrayList(NumChars);
for (int i = arr.Count; i > 0; i--)
{
if (arr[i - 1].ToString() == "0")
{
arr.RemoveAt(i - 1);
}
else
{
break;
}
}
if (arr.Count > 0)
{
string Num1 = "";
for (int i = 0; i < arr.Count; i++)
{
Num1 += arr[i];
}
return Nums[0] + "." + Num1;
}
else
{
return Nums[0];
}
}
return strNumber.ToString();
}
return "";
}