/// <summary>
/// Get SHA512 Hash From String
/// </summary>
/// <param name="originalData"></param>
/// <returns></returns>
static public string GetHash512String(
string originalData)
{
string result =
string.Empty;
byte[] bytValue =
Encoding.UTF8.GetBytes(originalData);
SHA512 sha512 =
new SHA512CryptoServiceProvider();
byte[] retVal =
sha512.ComputeHash(bytValue);
StringBuilder sb =
new StringBuilder();
for (
int i =
0; i < retVal.Length; i++
)
{
sb.Append(retVal[i].ToString("x2"));
}
result =
sb.ToString();
return result;
}
/// <summary>
/// Dictionary Parse To String
/// </summary>
/// <param name="parameters">Dictionary</param>
/// <returns>String</returns>
static public string ParseToString(IDictionary<
string,
string>
parameters)
{
IDictionary<
string,
string> sortedParams =
new SortedDictionary<
string,
string>
(parameters);
IEnumerator<KeyValuePair<
string,
string>> dem =
sortedParams.GetEnumerator();
StringBuilder query =
new StringBuilder(
"");
while (dem.MoveNext())
{
string key =
dem.Current.Key;
string value =
dem.Current.Value;
if (!
string.IsNullOrEmpty(key) && !
string.IsNullOrEmpty(value))
{
query.Append(key).Append("=").Append(value).Append(
"&");
}
}
string content = query.ToString().Substring(
0, query.Length -
1);
return content;
}
/// <summary>
/// String Parse To Dictionary
/// </summary>
/// <param name="parameter">String</param>
/// <returns>Dictionary</returns>
static public Dictionary<
string,
string> ParseToDictionary(
string parameter)
{
String[] dataArry = parameter.Split(
'&');
Dictionary<
string,
string> dataDic =
new Dictionary<
string,
string>
();
for (
int i =
0; i <= dataArry.Length -
1; i++
)
{
String dataParm =
dataArry[i];
int dIndex = dataParm.IndexOf(
"=");
if (dIndex != -
1)
{
String key = dataParm.Substring(
0, dIndex);
String value = dataParm.Substring(dIndex +
1, dataParm.Length - dIndex -
1);
dataDic.Add(key, value);
}
}
return dataDic;
}
static public string Base64Encode(
string data)
{
string result =
data;
byte[] encData_byte =
Encoding.UTF8.GetBytes(data);
result =
Convert.ToBase64String(encData_byte);
return result;
}
static public string Base64Decode(
string data)
{
string result =
data;
string decode =
string.Empty;
UTF8Encoding encoder =
new UTF8Encoding();
Decoder utf8Decode =
encoder.GetDecoder();
byte[] todecode_byte =
Convert.FromBase64String(data);
int charCount = utf8Decode.GetCharCount(todecode_byte,
0, todecode_byte.Length);
char[] decoded_char =
new char[charCount];
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char,
0);
result =
new String(decoded_char);
return result;
}