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;  
        }  
Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | 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.
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 82,061 Reputation points Volunteer Moderator
    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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.