473,757 Members | 10,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.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 SHA1CryptoServi ceProvider
to create a hash value from a string.
The vb example outputs "A94A8FE5CCB19B A61C4C0873D391E 987982FBBD3"
The cs example outputs "5BAA61E4C9B93F 3F0682250B6CF83 31B7EE68FD8"
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
------------------------------------------------------------------------
SHA1CryptoServi ceProvider myHash=new SHA1CryptoServi ceProvider();
byte[] password = Encoding.ASCII. GetBytes("passw ord");
myHash.ComputeH ash(password);
foreach (byte thisByte in myHash.Hash)
Console.Write(t hisByte.ToStrin g("X2"));

Console.WriteLi ne();

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

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

Dim myHash As SHA1CryptoServi ceProvider = New
SHA1CryptoServi ceProvider

Dim bytePassword As Byte() = Encoding.ASCII. GetBytes("passw ord")
myHash.ComputeH ash(bytePasswor d)

For Each thisByte As Byte In myHash.Hash
Console.Write(t hisByte.ToStrin g("X2"))
Next

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

Mar 7 '06 #1
2 3709

"johnnyG" <jo*****@discus sions.microsoft .com> wrote in message
news:70******** *************** ***********@mic rosoft.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
SHA1CryptoServi ceProvider
to create a hash value from a string.
The vb example outputs "A94A8FE5CCB19B A61C4C0873D391E 987982FBBD3"
The cs example outputs "5BAA61E4C9B93F 3F0682250B6CF83 31B7EE68FD8"
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.S HA1CryptoServic eProvider;
var password := System.Text.Enc oding.ASCII.Get Bytes('password ');
myHash.ComputeH ash(password);
for thisByte: Byte in myHash.Hash do
begin
Console.Write(t hisByte.ToStrin g('X2'));
end;
Console.WriteLi ne;
end;

this is the result:
5BAA61E4C9B93F3 F0682250B6CF833 1B7EE68FD8
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..."A94A8FE 5CCB19BA61C4C08 73D391E987982FB BD3" 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 SHA1CryptoServi ceProvider
to create a hash value from a string.
The vb example outputs "A94A8FE5CCB19B A61C4C0873D391E 987982FBBD3"
The cs example outputs "5BAA61E4C9B93F 3F0682250B6CF83 31B7EE68FD8"
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
------------------------------------------------------------------------
SHA1CryptoServi ceProvider myHash=new SHA1CryptoServi ceProvider();
byte[] password = Encoding.ASCII. GetBytes("passw ord");
myHash.ComputeH ash(password);
foreach (byte thisByte in myHash.Hash)
Console.Write(t hisByte.ToStrin g("X2"));

Console.WriteLi ne();

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

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

Dim myHash As SHA1CryptoServi ceProvider = New
SHA1CryptoServi ceProvider

Dim bytePassword As Byte() = Encoding.ASCII. GetBytes("passw ord")
myHash.ComputeH ash(bytePasswor d)

For Each thisByte As Byte In myHash.Hash
Console.Write(t hisByte.ToStrin g("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
8845
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 array of size 20) to a value range of my choosing. If there is no such thing, would need some idea how to program this in C#.
6
4469
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
7206
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 physical main memory. It seems the way to derive a SHA1 value involves opening a file stream to the large file, passing it to a byte array, and passing the byte array to the .NET hash method. Does this load the entire file into main memory (within...
1
10138
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 for encrypting text strings using MD5 hash, but I cannot find a way to get this to work with images that exist in picture boxes. I am trying to get a hash for the image file, but not from the file but from the picture box as there is some editing...
2
4470
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Ê%' \Y7". Here is my code segment written in VB.NET Enterprise Architect: -------- Public Function MD5File(ByVal Filename As String) As String ' ' Read a file, produce an MD5 hashed key value in a String.
3
2023
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, but it does provide a rowid function. So, I am storing a dictionary of <string, long>, string being the rowid and long being a sum of the hash code for each column in the row. With this dictionary, it is very easy to determine if a row is...
1
1495
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, ByVal key As String) As String Dim des As New Security.Cryptography.TripleDESCryptoServiceProvider
1
3597
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 tutorial to help me with this issue I figured I'd make a post just in case someone else runs into the same issue. ....
3
5144
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 msdn and some news gropus but dont see any method for this. Can any one show me the way how do this? Thanks for help! Iguana
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.