using System.Security.Cryptography;
using System.Collections;
using System.Collections.Generic;
public static string GenerateHash(string secretKey, string value){
byte[] key = Encoding.ASCII.GetBytes(secretKey);
HMACSHA256 myhmacsha1 = new HMACSHA256(key);
byte[] byteArray = Encoding.ASCII.GetBytes(value);
MemoryStream stream = new MemoryStream(byteArray);
string computedHash = myhmacsha1.ComputeHash(stream).Aggregate("", (s, e) => s + String.Format("{0:x2}", e), s => s);
public static string GetHashOfObjectValues(object ob, string key) {
SortedDictionary<string, string> dict = new SortedDictionary<string, string>();
PropertyInfo[] properties = ob.GetType().GetProperties();
foreach (PropertyInfo property in properties)
dict.Add(property.Name, (string) property.GetValue(ob, null));
StringBuilder builder = new StringBuilder();
var list = dict.Keys.ToList();
list.Sort(StringComparer.Ordinal);
foreach (string k in list)
Console.WriteLine(k +" " + dict[k]);
builder.AppendFormat("{0}",dict[k]);
string concatenatedString = builder.ToString();
Console.WriteLine("\nConcatenatedString: {0}", concatenatedString);
hash = GenerateHash(key, concatenatedString);
public static void Main(string[] args)
UserRequest request = new UserRequest();
string hash = GetHashOfObjectValues(request, "abcd+1234");
Console.WriteLine("\nhash: {0}", hash);
public class UserRequest{
public string AppVersion{ get; set; } ="4fgJIWGpawo=";
public string LoginBy { get; set; } ="5Vs3cRQk5o8=";
public string LoginName{ get; set; } ="YcW5WWhKiKw=";
public string PIN { get; set; } ="BRciD5TDuXw=";
public string Latitude{ get; set; } ="k0qr25VkyRoMdgDbKhMLDA==";
public string DeviceOS{ get; set; } ="8cWtH/dXJcQ=";
public string Longitude { get; set; } = "6INLDcs7+ljmlba08bNCdg==";
public string SessionID{ get; set; } ="8JiuqnOKxotEIN9QEsygRmPVJmZ5mLpMTHASJgtcEHI3zd2KuuI7kg==";
public string Location{ get; set; } ="1EACaP/omt3ggJHDp8iR5ZA/r8D+ZeCoaAv8Hy3gUkg=";
public string Password {get;set;}="ZKPgpCGMeJQ8Ms/7jPavXg==";