sha1 problem

Discussion in 'ASP .Net Security' started by Linda, Oct 20, 2004.

  1. Linda

    Linda Guest

    I'm I'm trying to compare 2 hash values using sha1 one written in vb.net
    and the other in Python.

    The value I get in my vb.net code does not match the python code, or any
    other hash calulator I have used.

    Here is the .net code:
    -----------------------------------------------
    Dim UE As New UnicodeEncoding
    Dim SHAhash As New SHA1Managed
    Dim SHA1HASHValue() As Byte
    Dim MessageBytes As Byte() = UE.GetBytes(TB_Input.Text)
    SHA1HASHValue = SHAhash.ComputeHash(MessageBytes)
    Dim b As Byte
    Dim strHex As String
    For Each b In SHA1HASHValue
    strHex += String.Format("{0:x2}", b)
    Next
    LB_Output.Text = strHex
    ----------------------------------------------------------------------------
    --------
    example: If I use a text value of "a"
    Run value in .net is: 0a04b971b03da607ce6c455184037b660ca89f78
    compared to a hash calulator: 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8
    ----------------------------------------------------------------------------
    -----------------------------------
    any ideas what is wrong here?
     
    Linda, Oct 20, 2004
    #1
    1. Advertising

  2. I get the same value as your hash calculator when I use ASCIIEncoding or
    UTF8Encoding. Therefore, the question is how is the python code converting
    your string to an array of bytes. Each of those encodings will produce
    different byte arrays, depending on what's in the source string. ASCII and
    UTF8 will be the same for all ASCII characters, but all three will be
    different for non-ASCII characters.

    These string->Byte() conversion issues seem to cause the most problems for
    people doing cryptography work.

    Joe K.

    "Linda" <> wrote in message
    news:...
    > I'm I'm trying to compare 2 hash values using sha1 one written in vb.net
    > and the other in Python.
    >
    > The value I get in my vb.net code does not match the python code, or any
    > other hash calulator I have used.
    >
    > Here is the .net code:
    > -----------------------------------------------
    > Dim UE As New UnicodeEncoding
    > Dim SHAhash As New SHA1Managed
    > Dim SHA1HASHValue() As Byte
    > Dim MessageBytes As Byte() = UE.GetBytes(TB_Input.Text)
    > SHA1HASHValue = SHAhash.ComputeHash(MessageBytes)
    > Dim b As Byte
    > Dim strHex As String
    > For Each b In SHA1HASHValue
    > strHex += String.Format("{0:x2}", b)
    > Next
    > LB_Output.Text = strHex
    > ----------------------------------------------------------------------------
    > --------
    > example: If I use a text value of "a"
    > Run value in .net is: 0a04b971b03da607ce6c455184037b660ca89f78
    > compared to a hash calulator: 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8
    > ----------------------------------------------------------------------------
    > -----------------------------------
    > any ideas what is wrong here?
    >
    >
     
    Joe Kaplan \(MVP - ADSI\), Oct 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dil via .NET 247

    SHA1 length of resulting hash

    Dil via .NET 247, Aug 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    18,085
    Dil via .NET 247
    Aug 4, 2004
  2. Al Murphy

    SHA1 hash generator in hex

    Al Murphy, Mar 2, 2004, in forum: Java
    Replies:
    5
    Views:
    28,045
    darkzak
    Jan 7, 2009
  3. Rafal 'Raf256' Maj

    md5/sha1

    Rafal 'Raf256' Maj, Jul 5, 2003, in forum: C Programming
    Replies:
    2
    Views:
    561
    Shill
    Jul 5, 2003
  4. LMZ
    Replies:
    5
    Views:
    638
    Martin v. Löwis
    Apr 6, 2008
  5. Adam Tauno Williams
    Replies:
    2
    Views:
    921
    Stefan Behnel
    Dec 30, 2010
Loading...

Share This Page