Re: SHA1 encoding differences with FormsAuthentication and SHA1CryptoServiceProvider

From: Super Julius (super_julius_at_yahoo.com)
Date: 05/12/04


Date: Wed, 12 May 2004 09:21:29 -0700

Thanks Hernan for your answer.

You pointed right the issue. The problem was my convert to hex value
with Convert.ToString(b, 16).

I have not tested your solution as I fixed the issue just before your
post :-) by using String.Format

Anyway I guess this can be relevant to other folks...

Here is the new code with

private string Hash(string toHash)
{
        string hashed = "";

        SHA1 sha1 = new SHA1CryptoServiceProvider();
        byte[] hash =
sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(toHash));
                        
        foreach(byte b in hash)
                hashed += String.Format("{0,2:X2}", b);

        return hashed;
}

Cheers
Julius

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: Darn Garden Gnomes
    ... I couldn't post.For some reason the hex has been broken.I'm back ... in.I've exchanged several emails with the folks at Google.They kept ...
    (alt.smokers.pipes)
  • Re: 010 is 8 and not 10 :(
    ... David Mathog wrote: ... Hex is indicated by a zero followed by a letter 'x', I suggest octal could have been indicated by a zero followed by a letter 'o'... ... about you folks, but I try to never mix "oh" and "zero" in variable names specifically to avoid this particular problem. ...
    (comp.lang.c)