Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default sha1 problem

    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 Guest

  2. Similar Questions and Discussions

    1. Digest::SHA1 b64digest weirdness
      This is really bizzaro. Here's my code: use Digest::SHA1; $password = "garbage"; my $ctx = Digest::SHA1->new; $ctx->add($password); my...
    2. Javascript::SHA1 V 1.01
      The pure Perl module Javascript::SHA1 V 1.01 is available immediately from CPAN, and from http://savage.net.au/Perl-modules.html. On-line docs,...
    3. SHA1 digest
      Dear all, I used Digest::SHA1 module to produce a digest on a message. The digest I get by calling sha1($msg) is a binary data in 20 bytes long....
    4. Decrypt string encrypted with SHA1
      No, it is not possible. SHA1 is a hashing algorithm and as any other hashing algorithm (e.g. MD5, SHA-256, etc) it does not support decryption. ...
    5. md5 / sha1 - Any real difference?
      Folks, I use md5 hash with some of my cookies and occassionally a hidden form field - I know the physical data on my network is insecure (unless...
  3. #2

    Default Re: sha1 problem

    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" <lindan@analyticinnovations.com> wrote in message
    news:uajwIkrtEHA.3628@tk2msftngp13.phx.gbl...
    > 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\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139