473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

.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 3682

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joseph Lee | last post by:
Dear All, Is there a function in C# that will hash code a large byte array into an int value? I am searching for a hash function that will convert any size data(as for me the input is a byte...
6
by: Chang | last post by:
How to get SHA1 or MD5 of a big file (+5MB - 20GB) as I can't read 20GB into memory. -- Chang.
5
by: Michael H | last post by:
Hi all, I guess I don't fully understand how a SHA1 hash value is calculated in C# / .NET for a large file... I'm trying to calculate SHA1 values for large files that are much larger than my...
1
by: sympatico | last post by:
Hi, I am trying to compare 2 images to check if they are exactly identical (in terms of data), I thought this would be quicker than analysing pixels of the images. I have found lots of examples...
2
by: Shaun Merrill | last post by:
This function doesn't seem to be giving me the appearance I expect. This should appear more like "1ba442ab45c8002a86d068d1c1748e44" but it looks really cryptic and screwy, like "­óìØLÜzrVÊ%'...
3
by: Brian | last post by:
I know this is the wrong way to do it, but maybe someone can tell me the right way to do it... I have two different databases that I need to synchronize. The database doesn't have keys exactly,...
1
by: tshad | last post by:
I have a function I am using to encrypt Keys and it doesn't seem to use the Hash I asked for. ************************************ Public Shared Function TripleDESEncode(ByVal value As String,...
1
by: Wayne Deleersnyder | last post by:
Hi All, I was going to write and ask if someone could help me fix the formatting of my output for hash values, but I believe I got it right now. But, because I couldn't find any website or...
3
by: Iguana | last post by:
Hi! I create application in csharp, .net 2.0. I must get (decode) from SignedXml.Signature.SignatureValue hash. This hash I need to send to TSA with TSP RFC 3161. I have spend lot of time read...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.