473,714 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hashing and Encryption

Hi,
What is the difference between Hashing and Encryption ?

Aug 30 '06 #1
6 2255
Ultra-simple definition:

Hashing is the process of extracting a unique number from an object.
GetHashCode, which is defined in System.Object, is an example present in all
..NET classes (since Object is the "Mother Function"). You cannot reconstruct
an object from its hash- it's a one-way deal.

Encryption on the other hand is the process of transforming an object to a
format where it can only be reconstructed by decrypting it, normally by the
use of a private key or a public / private key pair. Encryption, unlike
hashing, is 100% reversible.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jayender" wrote:
Hi,
What is the difference between Hashing and Encryption ?

Aug 30 '06 #2
Thats wonderful, Peter.. peice of CAKE..

Thanks,
Jay

Peter wrote:
Ultra-simple definition:

Hashing is the process of extracting a unique number from an object.
GetHashCode, which is defined in System.Object, is an example present in all
.NET classes (since Object is the "Mother Function"). You cannot reconstruct
an object from its hash- it's a one-way deal.

Encryption on the other hand is the process of transforming an object to a
format where it can only be reconstructed by decrypting it, normally by the
use of a private key or a public / private key pair. Encryption, unlike
hashing, is 100% reversible.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jayender" wrote:
Hi,
What is the difference between Hashing and Encryption ?
Aug 30 '06 #3
Peter Bromberg [C# MVP] <pb*******@yaho o.nospammin.com wrote:
Hashing is the process of extracting a unique number from an object.
GetHashCode, which is defined in System.Object, is an example present in all
.NET classes (since Object is the "Mother Function"). You cannot reconstruct
an object from its hash- it's a one-way deal.
Slight wrinkle - hashing does *not* give a unique number. It generally
can't, because the size of the hash space is usually much smaller than
the size of the original object space.

For instance, you could have multiple strings which give the same
hashcode. A hashcode is used as a first approximation towards matching
- if two objects have different hashcodes, they're definitely
different; if two objects have the same hashcode, they *may* be the
same.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 4 '06 #4
Sure, two objects having the same hash code aren't *guaranteed* to be
the same, but with strong hash algorithms like 128-bit SHA-2, isn't it
safe to say that the odds of finding two objects that aren't the same,
but that have the same SHA-2 hash code, are insanely small? So small
that, for practical purposes, we can assume that they are the same
object?

Maybe I'm confusing the fact that it is currently "computationall y
impossible" (read: would take forever) to search for another object
with the same SHA-2 hash code, with the chances of hitting one by
accident. Intuitively, it sounds nearly the same to me: If the chances
of deliberately finding another object with the same SHA-2 hash code
are so small, shouldn't the chances of finding one by accident be even
smaller?

If the user asking the original question has less than a billion
objects that they are hashing and comparing, shouldn't it be safe to
say that there won't be any collisions, if they use a good 128-bit
hash code or more? (There's 256-bit SHA-2 in the .NET FX isn't there?)

On Mon, 4 Sep 2006 21:18:22 +0100, Jon Skeet [C# MVP]
<sk***@pobox.co mwrote:
>Peter Bromberg [C# MVP] <pb*******@yaho o.nospammin.com wrote:
>Hashing is the process of extracting a unique number from an object.
GetHashCode, which is defined in System.Object, is an example present in all
.NET classes (since Object is the "Mother Function"). You cannot reconstruct
an object from its hash- it's a one-way deal.

Slight wrinkle - hashing does *not* give a unique number. It generally
can't, because the size of the hash space is usually much smaller than
the size of the original object space.

For instance, you could have multiple strings which give the same
hashcode. A hashcode is used as a first approximation towards matching
- if two objects have different hashcodes, they're definitely
different; if two objects have the same hashcode, they *may* be the
same.
--
Alex Leblanc
Xceed Software Inc.
http://www.xceedsoft.com

Check out our multi-talented Windows Forms.NET grid with built-in reporting.

Email: xL*******@xceed soft.com (remove the first 'x')
Sep 7 '06 #5
AlexL [Xceed] <xL*******@xcee dsoft.comwrote:
Sure, two objects having the same hash code aren't *guaranteed* to be
the same, but with strong hash algorithms like 128-bit SHA-2, isn't it
safe to say that the odds of finding two objects that aren't the same,
but that have the same SHA-2 hash code, are insanely small? So small
that, for practical purposes, we can assume that they are the same
object?
For SHA-2, yes - but Peter's comment was a general one about hashing as
a process. I have seen people assume that the hash code returned by
object.GetHashC ode() is unique (indeed, complaining that there is
supposedly a bug in the framework because two strings give the same
hash code) so I thought it worth pointing out the slight flaw in his
description.

<snip>

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 7 '06 #6
Ok - I just wanted to know if I had understood hashing correctly
myself, and if yes, bring up the mention of SHA-2 in there as another
possibility. I didn't mean to imply that your own reply was
incorrect!

On Thu, 7 Sep 2006 22:05:52 +0100, Jon Skeet [C# MVP]
<sk***@pobox.co mwrote:
>AlexL [Xceed] <xL*******@xcee dsoft.comwrote:
>Sure, two objects having the same hash code aren't *guaranteed* to be
the same, but with strong hash algorithms like 128-bit SHA-2, isn't it
safe to say that the odds of finding two objects that aren't the same,
but that have the same SHA-2 hash code, are insanely small? So small
that, for practical purposes, we can assume that they are the same
object?

For SHA-2, yes - but Peter's comment was a general one about hashing as
a process. I have seen people assume that the hash code returned by
object.GetHash Code() is unique (indeed, complaining that there is
supposedly a bug in the framework because two strings give the same
hash code) so I thought it worth pointing out the slight flaw in his
description.

<snip>
--
Alex Leblanc
Xceed Software Inc.
Sep 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3007
by: snowteo | last post by:
Hi,I have to do this exercises can you help me: 1)Write a program to implement exetendible hashing.If the table is small enough to fin in main memory,how does its performance compare with open and closed hasing? 2)A basic program consists of a series of statements,each of which is numbered in ascending order.Control is passed by use of a goto or gosub and a statement number.Write a program that reads in a legal BASIC program and renumbers...
4
2030
by: macluvitch | last post by:
hello folks, do you have any idea how gperf generates the numeric table ? I know that it uses perfect hashing for speeding up look up. any link, trick will be really very appreciated thanks in advance
11
3431
by: Wm. Scott Miller | last post by:
Hello all! We are building applications here and have hashing algorithms to secure secrets (e.g passwords) by producing one way hashes. Now, I've read alot and I've followed most of the advice that made sense. One comment I've seen alot about is "securing the hashing routine" but no-one explains how to accomplish this. So how do I secure my hashing routine? Do I use code access security, role based security, ACLs, etc or combination?...
19
3832
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as dictionary keys, based on their content, not their identity. Is this feasible using the arrays directly, or do I need to wrap them in a struct that handles GetHashCode and Equal? If so, is such a wrapper present in the standard class library?
8
4574
by: Maya | last post by:
Hello all, I'm using MD5 hashing in my application to give unique values to huge list of items my application receives, originally every item's name was difficult to use as an id for this item although its unique but because it had certain characters and variable lengths I ended up using MD5 hashing of the name.
1
1055
by: Jayender | last post by:
Hi, What is the difference between Hashing and Encryption ?
1
4413
by: Tinku | last post by:
Hi friends I know Static Hashing and i know about Dynamic Hashing, still i have problem to make program with Dynamic Hashing I am new in "C" world, please help me, my problem is: i have to make program in Dynamic hashing i have to store int value in nodes user only enter int value by this value i have to find hash key and make symbol table my struct are
15
3003
by: Vinodh | last post by:
I am reading about hashing techniques. The map data structure available in C++ STL uses hashing techniques?
24
1951
by: Johnny Jörgensen | last post by:
I'm wondering (and hoping that somebody will be able to answer this): If I calculate the hash value of files (either MD5 or SHA1), can I then be sure that: 1) Two files with the same hash value are in fact identical? 2) Two different files will NEVER have the same hash value? 3) If two files have the same MD5 hash value, they will ALSO have the same
0
8810
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
8712
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
9316
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9078
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
7955
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5959
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
4729
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3160
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
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.