farina
farina

Reputation: 3576

How can I unhash a hash using C#?

Can someone reverse this handy hash code I'm using?

using System.Security.Cryptography;

public static string EncodePasswordToBase64(string password)
{  byte[] bytes   = Encoding.Unicode.GetBytes(password);
   byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
   return Convert.ToBase64String(inArray);
}

Everything I end up doing fails horribly :(.

Upvotes: 3

Views: 6279

Answers (4)

Adisak
Adisak

Reputation: 6926

SHA is an NSA acronym for "Secure Hash Algorithm".

Secure Hashes are hard to reverse by definition -- otherwise they would not be Secure.

You need to use a reversible hash function if you want to be able to easily compute sources that will generate the same hash (and even then you might not get the original source due to hash collisions where more than one source input can result in the same hash output).

Upvotes: 0

JonnyLitt
JonnyLitt

Reputation: 773

You cannot un-hash SHA1, MD5, or any other one-way hash method unfortunately. Though it is possible to undo BASE-64.

Upvotes: 1

Matt
Matt

Reputation: 32292

The only real way of "unhashing" is using a rainbow table, which is a big table of hashes computed for all possible inputs. You look up the hash and get what was probably the original input.

http://en.wikipedia.org/wiki/Rainbow_table

Upvotes: 5

Noon Silk
Noon Silk

Reputation: 55112

No, you can't reverse a hash. The typical process is to compare other input to the hash you have, to check if they are the same.

Like (pseudo):

initial  = Hash(password);
possible = Hash("test");

if( initial == possible ){
    // we infer that password = "test"
}

But note that SHA1, SHA0, and MD5 should no longer be used; (due to various degrees of breaking in each). You should use SHA-2

Upvotes: 22

Related Questions