Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am integrating my asp .net web application with a payment gateway and in their documentaion they told to use the SHA512 algorithm for a string.
so i am using the SHA512 hash code as shown below and genrating the hash signature.
But the signature i am generating is different from their. SO i am getting an error.

So the question is

1) all the SHA512 algorithms produce same output?
Im my search they are not same
2) If there are many SHA512 algorithms then which one i want to use?
Can i ask the payment gateway people for the algorithm?
3) Is there any generic SHA512 algorithm that matches with all the remaining algorithms?

I am sorry if these questions seems to be funny. But i am new to this payment gateway integration.

Thanks in Advance

What I have tried:

public String computeHash(String message)
{
byte[] sourceBytes = Encoding.Default.GetBytes(message);
byte[] hashBytes = null;

hashBytes = SHA512Managed.Create().ComputeHash(sourceBytes);

StringBuilder sb = new StringBuilder();
for (int i = 0; i<hashBytes.Length; i++)
{
sb.AppendFormat("{0:x2}", hashBytes[i]);
}
return sb.ToString();
}
Posted
Updated 29-Dec-17 0:32am

1 solution

There are no multiple SHA512 algorithms; there is only one, the SHA512 algorithm. All SHA512 implementations should return the same bytes, otherwise they wouldn't be SHA512 implementations anymore.

But note that SHA512 takes bytes as input and outputs an array of hashed bytes. How these output bytes are encoded as a string, can differ. For example, you can encode them as hexadecimal or as base64. You say "In my search they are not the same"; the only thing that should differ, is the encoding of the output.

I don't know whether your code should encode the output as hexadecimal, base64 or something else. Refer to the documentation for that.
 
Share this answer
 
v2
Comments
Member 13142345 29-Dec-17 6:37am    
Thanks For the Response and Explanation.
In the documentation it is stated as hexadecimal. So how can my above code should be encoded to hexadecimal format. can you please help me with that.
Thomas Daniels 29-Dec-17 6:39am    
Your code seems to be working fine. The output is hexadecimal already.
Member 13142345 29-Dec-17 7:01am    
So can you suugest me a solution how to acheive that mismatch error if i am doing it as hex string.
Thomas Daniels 29-Dec-17 7:02am    
You could try uppercase hexadecimal. If that doesn't work, I'd contact the payment gateway system, they know way better what's going on.
Member 13142345 29-Dec-17 7:10am    
Did you mean to do this

return sb.ToString().ToUpper();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900