-1

I have the following string: TheString = 12424$456$06$4539527688361959$2017$188.98.78.191$

I want the SHA1 Hash of that string and for that I'm using the following code:

string TheSHA1Hash = BitConverter.ToString(new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(TheString)));

This is the output:

8F-BA-36-2C-FC-DE-31-B2-AC-66-07-37-2D-80-85-63-5A-33-35-F4

When I go to http://www.sha1-online.com/ and hash the string, this is the output, which is what I want:

8fba362cfcde31b2ac6607372d8085635a3335f4

It looks the same but it's not the same. How can I get the output I want?

halfer
  • 19,824
  • 17
  • 99
  • 186
frenchie
  • 51,731
  • 109
  • 304
  • 510
  • it looks like in lazy way, removing dashes and putting it in lower case will make you work done :D <3 – jace Dec 16 '16 at 02:04

2 Answers2

5

Just remove the dashes (with Replace()) and make lowercase (with ToLower()).

string TheSHA1Hash = BitConverter.ToString(new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(TheString))).Replace("-","").ToLower();

Here it is in a format that is a bit easier to read:

var hasher = new SHA1Managed();
var hash = hasher.ComputeHash(Encoding.UTF8.GetBytes(TheString));
var byteString = BitConverter.ToString(hash);
var theSHA1Hash = byteString.Replace("-","").ToLower();

See also this answer.

Community
  • 1
  • 1
John Wu
  • 50,556
  • 8
  • 44
  • 80
0

If you don't like the output of BitConverter (which includes dashes), you can roll your own array-to-hex converter. See the answers to this question to see how.

Community
  • 1
  • 1
John Wu
  • 50,556
  • 8
  • 44
  • 80