views:

17

answers:

1

Hi Guys,
I get string messages from the clients which needs to be authenticated in the server. I need to ensure that I (the server) got the exact string content which was sent by the client. I don't care about the client identity. Just the message. I thought of using hashcode or CRC algorithm.
Do you have any suggestions/best practices for it?

Thanks a lot,
Adi Barda

A: 

To make certain the string is identical, then yes, a hash will do the job. The only problem you will encounter is that if the server has nothing to match to, all you will have is that the string you have is the same as the string that was hashed.

Any language you are using in particular?

Here's an example in C#, which hashes a string then converts into Base64:

    public static string QHash(string str)
    {
        SHA512 SHA512HashCreator = SHA512.Create();

        byte[] EncryptedData = SHA512HashCreator.ComputeHash(Encoding.UTF8.GetBytes(str));

        StringBuilder qhash = new StringBuilder();

        for (int i = 0; i < EncryptedData.Length; i++)
        {
            qhash.Append(EncryptedData[i].ToString("X2"));
        }

        return qhash.ToString().ToUpper();
    }
Kyle Rozendo