using System;
using System.Collections.Generic;
using paytm;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Web;
public partial class GenerateChecksum : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //string[] keys = Request.Form.AllKeys;

            string msg = Request.Headers.GetValues("msg")[0];
            string key = Request.Headers.GetValues("key")[0];            

            //string msg = Request.QueryString["msg"];
            //string key = Request.QueryString["key"];
            String hash = string.Empty;
            hash = GetHMACSHA256(msg, key);
            CommonHelper.LogWriter("msg : " + msg + "\n key : " + key + "\n hash : " + hash, 1, "Billdesk CheckSum", HttpContext.Current.Request.Url.AbsoluteUri);
            Response.Write(hash);
        }
        catch (Exception)
        {

        }
    }

    public string GetHMACSHA256(string text, string key)
    {
        UTF8Encoding encoder = new UTF8Encoding();

        byte[] hashValue;
        byte[] keybyt = encoder.GetBytes(key);
        byte[] message = encoder.GetBytes(text);

        HMACSHA256 hashString = new HMACSHA256(keybyt);
        string hex = "";

        hashValue = hashString.ComputeHash(message);
        foreach (byte x in hashValue)
        {
            hex += String.Format("{0:X2}", x);
        }
        return hex;
    }    
}
