Hash Calculation in Request and Response in PayUMoney C# API
hashSequence =
key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt;
$hash = hash("sha512", $hashSequence);
Where salt is available on the PayUMoney dashboard.
Note: A blank udf field is to be used while computing hashSequence, even if a merchant is not passing any udf field in input request.
For the response hash, the sequence of variables is in reverse order as compared to payment request hash. Also, a status variable added between salt and udf1
Sequence
hashSequence = salt|status||||||udf5|udf4|udf3|udf2|udf1|email|firstname|productinfo|amount|txnid|key;
$hash = hash("sha512", $hashSequence);
Where salt is available on the PayUMoney dashboard.
Here is sample code for response hash calculation:-
bool isCheckSum = false;
var strhash = Request.Form["hash"];
var strstatus = Request.Form["status"];
var strfirstname = Request.Form["firstname"];
var stramount = Request.Form["amount"];
var strtxnid = Request.Form["txnid"];
var strkey = Request.Form["key"];
var strproductinfo = Request.Form["productinfo"];
var stremail = Request.Form["email"];
var stradditionalCharges = Request.Form["additionalCharges"];
string strudf1 = Request.Form["udf1"];
string strudf2 = Request.Form["udf2"];
string strudf3 = Request.Form["udf3"];
string strudf4 = Request.Form["udf4"];
string strudf5 = Request.Form["udf5"];
System.Security.Cryptography.SHA512Managed sha512 = new System.Security.Cryptography.SHA512Managed();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(strSALT + "|" + strstatus + "||||||" + strudf5 + "|" + strudf4 + "|" + strudf3 + "|" + strudf2 + "|" + strudf1 + "|" + stremail + "|" + strfirstname + "|" + strproductinfo + "|" + stramount + "|" + strtxnid + "|" + strkey);
byte[] hashBytes = sha512.ComputeHash(inputBytes);
byte[] hashValue;
string hex = "";
hashValue = sha512.ComputeHash(inputBytes);
foreach (byte x in hashValue)
{
hex += String.Format("{0:x2}", x);
}
if(strhash == hex)
{
isCheckSum = true;
}