顯示具有 C# 標籤的文章。 顯示所有文章
顯示具有 C# 標籤的文章。 顯示所有文章

2012年1月4日 星期三

C# SHA1 As PHP

public static string sha1(string input, bool rawOutput = false)
{
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
System.Security.Cryptography.SHA1Managed hash =
new System.Security.Cryptography.SHA1Managed();
byte[] output = hash.ComputeHash(encoder.GetBytes(input));
return rawOutput ?
Convert.ToBase64String(output) :
BitConverter.ToString(output).Replace("-", "").ToLowerInvariant();
}

C# UrlEncode To Uppercase

http://stackoverflow.com/questions/918019/net-urlencode-lowercase-problem

public static string UpperCaseUrlEncode(string s)
{
char[] temp = HttpUtility.UrlEncode(s).ToCharArray();
for (int i = 0; i < temp.Length - 2; i++)
{
if (temp[i] == '%')
{
temp[i + 1] = char.ToUpper(temp[i + 1]);
temp[i + 2] = char.ToUpper(temp[i + 2]);
}
}
return new string(temp);
}