I am writing a part of code to change string into hash
String hash = GetHashString("A"); //return 7FC56270E7A70FA81A5935B72EACBE29
My question is how can I get back "A" when I pass in the hash code ?
7FC56270E7A70FA81A5935B72EACBE29
Hashes are not meant to be reversible. If you want to compare its origin with another string, just hash the second one too and then compare their hashes.
Related
How to convert Md5Hash values to string..
i have convert string values to hash..
i have used the to method to convert MD5Hash to string
`
public static string ConvertStringtoMD5(string strword)
{
MD5 md5 = MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(strword);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString();
}
`
string has=ConvertStringtoMD5("prasad");
its returns hash value = 'c246ad314ab52745b71bb00f4608c82a'
using this hash values i need to get the string called prasad
how can i achive this, can you suggest to achive this..
Hashes are one-way. They are not designed to be unencoded once they are encoded. That being said, they can be cracked using Rainbow Tables. To create your own rainbow table in C#, you can look at this article.
Keep in mind that Rainbow Tables do have limitations and do not work 100% of the time. This is especially true if the MD5 hash has been salted.
Hashing functions are only one way functions - there is no way to get the input.
You could try using e.g. rainbow tables, but because number of possible hashes is limited, there is a chance that you will get another string with the same MD5 hash instead of the input.
Hashing is one way function. This means that you can't get the original input by using the hashed output.
One of the ways to compare if two inputs are the same is to hash the new input and check it against the already hashed output you already have, then simply check if the values are the same. Keep in mind, that in some algorithms, collisions can occur, which means two different inputs might generate the same output.
MD5 is a one-way hash, you cannot (without brute force techniques) obtain the original string from the hash.
You can't reverse MD5 method, it's a hashing algorithm. There are infinite values that can result in the same hash string.
I have code to generate SHA512 from string.
public static string GetCrypt(string text)
{
string hash = "";
SHA512 alg = SHA512.Create();
byte[] result = alg.ComputeHash(Encoding.UTF8.GetBytes(text));
hash = Encoding.UTF8.GetString(result);
return hash;
}
Now I must convert hash back to string. Any ideas how can it be done? Thank you.
Hashes are 1-way. You can't get it back (easily). you might want actual encryption.
Yes. Hashes are one-way. Please use symmetric encryption classes like RijndaelManaged.
Here is a RijndaelSimple class that I am using:
http://www.obviex.com/samples/encryption.asp
The cached version of the same link is here:
http://webcache.googleusercontent.com/search?q=cache:WyVau-XgIzkJ:www.obviex.com/samples/encryption.asp&hl=en&prmd=imvns&strip=1
You cant convert a hash back to string from which you computed the hash.
If you want it then you would have to compare the hash with each of the target strings hash.
If one of them matches with the hash,then that hash comes from the target string.
Its use: If you want to store passwords in database,you can store its hashes instead of passwords.So even if a hacker gets access to your database,he cant get the password cuz it is hashed.The only way to know the string through which we created the hash is to match it with the desired string!
A really simple question:
I am doing a simple thing. I have few string like:
string A = "usd";
And I want to get the hashcode in C#:
int audusdReqId = Convert.ToInt32("usd".GetHashCode());
Now how could I convert the 32-bit integer audusdReqId back to the string "usd"?
You cannot. A hash code does not contain all of the necessary information to convert it back to a string. More importantly, you should be careful what you use GetHashCode for. This article explains what you should use it for. You can't even guarantee that GetHashCode will return the same thing in different environments. So you should not be using GetHashCode for any cryptographic purposes.
If you are trying to create a binary representation of a string, you can use
var bytes = System.Text.Encoding.UTF8.GetBytes(someString);
This will give you a byte[] for that particular string. You can use GetString on Encoding to convert it back to a string:
var originalString = System.Text.Encoding.UTF8.GetString(bytes);
If you are trying to cryptographically secure the string, you can use a symmetric encryption algorithm like AES as Robert Harvey pointed out in the comments.
The purpose of the hashcode/hash function is that it has to be one way and that it cannot be converted back to the original value.
There are good reasons as to why this is so. A common usage would be password storage in a database for example. You shouldn't know the original value(the plain text password) and that is why you would normally use a hashcode to encode it one way.
There are also other usages as storing values to hashsets etc.
From this sample code from MSDN
http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx
The hash code for "abc" is: 536991770
But how to convert back the "536991770" to "abc"?
The is no way to get value from the hashcode. See hash-function definition.
Hash values are not used to uniquely identify the original value, have values are not unique for each type of the input value.
A hash function may map two or more
keys to the same hash value. In many
applications, it is desirable to
minimize the occurrence of such
collisions, which means that the hash
function must map the keys to the hash
values as evenly as possible.
You cannot. Hashes are one way.
The thing with hashes is that you loose information. Independent of the length of the string, the result is always an integer. This means e.g. that getting the has of a string of 10,000 characters will also result in an integer. It is of course impossible to get the original string back from this integer.
There is no way to "decrypt" the hash code. Amongst other reasons, because two different strings may very well produce the same hash code. That feature alone would make it impossible to reverse the process.
You cannot,
Even if you will have a table with all strings in the world and their hash code you wouldn't be able to achieve that since there are more string then ints (~4 billion ints) so there are several strings that result in the same hash code.
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 :(.
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
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
You cannot un-hash SHA1, MD5, or any other one-way hash method unfortunately. Though it is possible to undo BASE-64.
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).