SHA1 hash question

I have this method for hashing a string:

byte[] buffer = enc.GetBytes(text); SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider(); string hash = BitConverter.ToString( cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", ""); return hash; 

My question is:

Is the resulting hash always the same for the same string?

I wrote a couple of days ago, and it seems that now it has led to another hash, but I'm not sure.

+4
source share
3 answers

Yes, the same plaintext string will hash to the same SHA1 hash each time.

+10
source

As long as the bytes are the same, you will get exactly the same hash. Note that special characters and spaces are also bytes.

Wikipedia Link

+3
source

Id depends! The same string text string will be hashes for the same SHA1 hash if you use the same encoding! Using different encodings will result in different SHA1 hashes.

0
source

Source: https://habr.com/ru/post/1302489/


All Articles