CodingWanted: VB.NET user

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Peter (BOUGHTONP)  
 To:  ALL
30763.1 
Can someone please confirm what the output of this function is:
VB code:
Imports System.Security.Cryptography
Private Function ComputeHash(ByVal Key As String) As String
	Dim objSHA1 As New SHA1CryptoServiceProvider
	objSHA1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(Key.ToCharArray))
	Dim buffer() As Byte = objSHA1.Hash
	Dim HashValue As String = System.Convert.ToBase64String(buffer)
	Return HashValue
End Function

When the value "SENTRYORD01154321SENTRYORD01154321" is passed in.

Also, can anyone confirm if the SHA1CryptoServiceProvider.ComputeHash bit is using 28-bit SHA-1 encryption or something else?

Thanks.
0/0
 Reply   Quote More 

 From:  Ally  
 To:  Peter (BOUGHTONP)     
30763.2 In reply to 30763.1 
Good lord.

I dunno if this'll help.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Ally     
30763.3 In reply to 30763.2 
It doesn't itself, but a page linked from it does:
quote:
The hash size for the SHA1 algorithm is 160 bits.


Which is 20 bytes, not 28, and that probably explains why the expected result was different.

Ta.
0/0
 Reply   Quote More 

 From:  Mal (BAD)  
 To:  Peter (BOUGHTONP)     
30763.4 In reply to 30763.3 
I was under the impression that a SHA1 hash was always 20 bytes in length.

back in a flash! and as dangerous as ever...
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mal (BAD)     
30763.5 In reply to 30763.4 
As far as I can tell, you're right.

I'm trying to figure out where 28 characters comes into things, but I've not figured it out yet. :S
0/0
 Reply   Quote More 

 From:  Mal (BAD)  
 To:  Peter (BOUGHTONP)     
30763.6 In reply to 30763.5 
Which 28 characters are those then?

back in a flash! and as dangerous as ever...
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mal (BAD)     
30763.7 In reply to 30763.6 
The ones that this Hash function returns:
# SHA: Generates a 28-character string using the Secure Hash Standard SHA-1 algorithm specified by Nation Institute of Standards and Technology (NIST) FIPS-180-2.
# SHA-256: Generates a 44-character string using the SHA-256 algorithm specified by FIPS-180-2.
# SHA-384: Generates a 64-character string using the SHA-384 algorithm specified by FIPS-180-2.
# SHA-512: Generates an 88-character string using the SHA-1 algorithm specified by FIPS-180-2.
0/0
 Reply   Quote More 

 From:  Mal (BAD)  
 To:  Peter (BOUGHTONP)     
30763.8 In reply to 30763.7 

Weird. What do you get when you pass your test string then?

 

It should be: 303569615317dc99a7029efb15a01a43a5ad39d3


back in a flash! and as dangerous as ever...
0/0
 Reply   Quote More 

 From:  Mal (BAD)  
 To:  Peter (BOUGHTONP)     
30763.9 In reply to 30763.7 
Actually, one of the comments at the bottom of that page indicates that the documented returned string lengths are wrong and you actually get 40 characters when using SHA1, which is correct.

back in a flash! and as dangerous as ever...
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mal (BAD)     
30763.10 In reply to 30763.8 
Can't remember, but it wasn't Hex, it was the one that tends to end in = or ==.

Ah, could it be non-Hex base-16? 16*2 +8 = 40 Hex characters, like what you have there.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mal (BAD)     
30763.11 In reply to 30763.9 
Yeah, but the example I was running was returning 28 characters, as was the expected output from that VB function, but they were a different 28 characters, so it must have been that one function is hashing before converting to Base64 (I don't get that - how does 20 in Base64 make 28? :S) and the other one was... doing something else but still producing a Base64 number.
0/0
 Reply   Quote More 

 From:  Mal (BAD)  
 To:  Peter (BOUGHTONP)     
30763.12 In reply to 30763.11 
Now I understand. Still odd though.

back in a flash! and as dangerous as ever...
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mal (BAD)     
30763.13 In reply to 30763.12 

Ah, yeah, that table helps it make sense.

 

But yes very odd.

 


Now I can go to bed without it keeping me awake all night. :]

0/0
 Reply   Quote More 

Reply to All    
 

1–13

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats