Reply
Highlighted
Member
Posts: 1
Registered: ‎04-15-2019

Received Hash and generated hash not matching

Hello,

I am using Authorized.net with c#. I have getting some problem at the time of transaction. Transaction received hash and generated received hash not matching. Can any one help me regarding this  where I am wrong? Thanks in advance.
My code is given below:

 

Received hash:

 

string key =Convert.ToString("abc123456");

string value = Convert.ToString(loginID + "^" + seq + "^" + timeStamp + "^" + amount + "^");

string fingerprint = HMACSHA512(key, value);

 

public string HMACSHA512(string key, string textToHash)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentNullException("HMACSHA512: key", "Parameter cannot be empty.");
if (string.IsNullOrEmpty(textToHash))
throw new ArgumentNullException("HMACSHA512: textToHash", "Parameter cannot be empty.");
if (key.Length % 2 != 0 || key.Trim().Length < 2)
{
throw new ArgumentNullException("HMACSHA512: key", "Parameter cannot be odd or less than 2 characters.");
}
try
{
byte[] k = Enumerable.Range(0, key.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(key.Substring(x, 2), 16))
.ToArray();
HMACSHA512 hmac = new HMACSHA512(k);
byte[] HashedValue = hmac.ComputeHash((new System.Text.ASCIIEncoding()).GetBytes(textToHash));
return BitConverter.ToString(HashedValue).Replace("-", string.Empty);
}
catch (Exception ex)
{
throw new Exception("HMACSHA512: " + ex.Message);
}
}

 

Received hash is given below: "9037CD31FADCCAD8EDFBAF97E27D58EA354FF3FB29060E09BC7C2BF7BD29F2F7D1E5F3CA96EEC2BB27B8BBA7677970851A0E65867E04BE812EC437A631E6122F"

 

Now the generated hash value process is given below:

 

string key = Convert.ToString("abc123456");

string str_generated_hash = HMACSHA512(key, "^" + x_login + "^" + x_trans_id + "^" + x_amount + "^");

 

I am using same function HMACSHA512 as given above. The generated hash value is "BF904ED074B81754725D1E7E547EBFC5B89EE6A6DEE1A08B79C536E1652D617D8644C7948B269A8C542D5D6783EF748A9000D51DE4BD94CFDF30CA85C4EE8B4B" which is different from received hash value.