locked
Different hash values returned for same string RRS feed

  • Question

  • User1999407103 posted

     I am using different calls to the same crypto provider that return different hashes.  I need to have the same hashes in order for my program to work.  Below is the code I am executing.  I am open to any suggesions.

     

    mystring = EncryptData(User.Identity.Name.Substring(4));

     

    mystring2 = EncryptData(User.Identity.Name.Substring(4));

     

    areEqual = mystring.SequenceEqual(mystring2);

    byte[] mystring;byte[] mystring2;bool areEqual;

     private byte[] EncryptData(string myInput)

    {

    byte[] valueToHash = Encoding.UTF8.GetBytes(myInput);

    return generatedHash = Cryptographer.CreateHash(hashProvider, valueToHash);

    }

    Thursday, December 2, 2010 5:50 PM

Answers

  • User1999407103 posted

    I solved the problem by not using the cryptography block at all.  Below is the code I used.  The hash value is now the same on multiple hash calls for the same string.

    string verifiableMesage = "It was the best of times, it was the worst of times. ";
    SHA1Managed sha = new SHA1Managed() ;
    byte[] hashValue =
        sha. ComputeHash(System. Text.ASCIIEncoding. ASCII. GetBytes(verifiableMesage) ) ; 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 3, 2010 9:46 AM