470,835 Members | 1,902 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,835 developers. It's quick & easy.

.NET hash/Cryptography newby question

Greetings,
I'm studying for the 70-330 Exam using the MS Press book by Tony Northrup
and there are 2 side-by-side examples of using the SHA1CryptoServiceProvider
to create a hash value from a string.
The vb example outputs "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3"
The cs example outputs "5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8"
for the string "password"
Question: do the 2 applications use different automatic "salts" or "seeds"
to generate the hash? More specifically, why are they different? Is there no
single SHA1 hash for the string "password"?
I know these are newby questions, but I'm having diffculty getting my head
around what exactly is going on with the hash process...

I'll include the source code for both programs...

// cs version
------------------------------------------------------------------------
SHA1CryptoServiceProvider myHash=new SHA1CryptoServiceProvider();
byte[] password = Encoding.ASCII.GetBytes("password");
myHash.ComputeHash(password);
foreach (byte thisByte in myHash.Hash)
Console.Write(thisByte.ToString("X2"));

Console.WriteLine();

//-----------------------------------------------------------------------------------

' vb version
------------------------------------------------------------------------

Dim myHash As SHA1CryptoServiceProvider = New
SHA1CryptoServiceProvider

Dim bytePassword As Byte() = Encoding.ASCII.GetBytes("password")
myHash.ComputeHash(bytePassword)

For Each thisByte As Byte In myHash.Hash
Console.Write(thisByte.ToString("X2"))
Next

'---------------------------------------------------------------------------------------
Any help in understainding greatly appreciated...I'm sitting for the exam
this Friday the 10th
jg

Mar 7 '06 #1
2 3549

"johnnyG" <jo*****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Greetings,
I'm studying for the 70-330 Exam using the MS Press book by Tony Northrup
and there are 2 side-by-side examples of using the
SHA1CryptoServiceProvider
to create a hash value from a string.
The vb example outputs "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3"
The cs example outputs "5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8"
for the string "password"
Question: do the 2 applications use different automatic "salts" or "seeds"
to generate the hash? More specifically, why are they different? Is there
no
single SHA1 hash for the string "password"?
I know these are newby questions, but I'm having diffculty getting my head
around what exactly is going on with the hash process...


This is very strange...
I recreated the program in Chrome for .net 2.0:

class method ConsoleApp.Main;
begin
var myHash := new System.Security.Cryptography.SHA1CryptoServiceProv ider;
var password := System.Text.Encoding.ASCII.GetBytes('password');
myHash.ComputeHash(password);
for thisByte: Byte in myHash.Hash do
begin
Console.Write(thisByte.ToString('X2'));
end;
Console.WriteLine;
end;

this is the result:
5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
The same as the C# program...

I wonder why the VB.net app is outputting an other hashcode...

Regards,

Jeroen Vandezande
Mar 7 '06 #2
oops..."A94A8FE5CCB19BA61C4C0873D391E987982FBBD3" is the hash for "test" not
"password"...I'm shot...thanks for your help...

Due to your research I am now confident that strings always hash to the same
value when the same hash algo is used.

"johnnyG" wrote:
Greetings,
I'm studying for the 70-330 Exam using the MS Press book by Tony Northrup
and there are 2 side-by-side examples of using the SHA1CryptoServiceProvider
to create a hash value from a string.
The vb example outputs "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3"
The cs example outputs "5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8"
for the string "password"
Question: do the 2 applications use different automatic "salts" or "seeds"
to generate the hash? More specifically, why are they different? Is there no
single SHA1 hash for the string "password"?
I know these are newby questions, but I'm having diffculty getting my head
around what exactly is going on with the hash process...

I'll include the source code for both programs...

// cs version
------------------------------------------------------------------------
SHA1CryptoServiceProvider myHash=new SHA1CryptoServiceProvider();
byte[] password = Encoding.ASCII.GetBytes("password");
myHash.ComputeHash(password);
foreach (byte thisByte in myHash.Hash)
Console.Write(thisByte.ToString("X2"));

Console.WriteLine();

//-----------------------------------------------------------------------------------

' vb version
------------------------------------------------------------------------

Dim myHash As SHA1CryptoServiceProvider = New
SHA1CryptoServiceProvider

Dim bytePassword As Byte() = Encoding.ASCII.GetBytes("password")
myHash.ComputeHash(bytePassword)

For Each thisByte As Byte In myHash.Hash
Console.Write(thisByte.ToString("X2"))
Next

'---------------------------------------------------------------------------------------
Any help in understainding greatly appreciated...I'm sitting for the exam
this Friday the 10th
jg

Mar 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Joseph Lee | last post: by
6 posts views Thread by Chang | last post: by
5 posts views Thread by Michael H | last post: by
1 post views Thread by sympatico | last post: by
2 posts views Thread by Shaun Merrill | last post: by
3 posts views Thread by Brian | last post: by
1 post views Thread by tshad | last post: by
1 post views Thread by Wayne Deleersnyder | last post: by
3 posts views Thread by Iguana | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.