Facing issue with hashing in c#

Sahu, Jagannath 1 Reputation point
2022-09-11T19:20:27.52+00:00

Hi,
I am facing an issue with the hashing.
I am using the below code for hashing.
i have to hash certain number and inserting in to a database table.
i am using two applications . in both the application i am using the same number which has to be hashed and the same secret key.
ideally it should save same value in database, but both the hashed values are different, its very strange.

239819-differenthashvalue.jpg

Any help is appreciated.

 public static byte[] GetHashValue(string text, string secret)  
        {  
            string hash = text + secret;  
  
            byte[] tmpSource;  
            byte[] tmpHash;  
            //Create a byte array from source data  
            tmpSource = Encoding.ASCII.GetBytes(hash);  
  
            //Compute hash based on source data  
            using (var md5 = MD5.Create())  
            {  
                tmpHash = md5.ComputeHash(tmpSource);  
            }  
  
            return tmpHash;  
        }  
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,346 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,041 Reputation points
    2022-09-14T15:55:47.307+00:00

    most likely you have a bug where you are not sending the same string and secret. just add log to see.

    0 comments No comments