tags:

views:

70

answers:

2

Hello there,

I have problem when trying get hash string in c#.

I already try research in few website, but most them using file to get hash. Even some there , for string, there bit complex. And other one I found it for window authentication for web like this:

FormsAuthentication.HashPasswordForStoringInConfigFile(tbxPassword.Text.Trim(), "md5")

Actually my purpose using hash string to more secure in redirect page to get filename wish to download from query string after hashing.

How to get hash in string.

Example:

string file  = "username";
string hash = ??????(username); 

Another question, it possible using another hashing "md5" algorithm.

Please help

regard.

+1  A: 

I think what you're looking for is not hashing but encryption. With hashing, you will not be able to retrieve the original filename from the "hash" variable. With encryption you can, and it is secure.

See http://stackoverflow.com/questions/667887/aes-in-asp-net-with-vb-net for more information about encryption in .NET.

Pieter
yes, i think is encryption, but i just wish to compare result hash. After redirect page.
Edy Cu
What do you want to compare the hashed filename with?
Pieter
+1  A: 

I don't really understand the full scope of your question, but if all you need is a hash of the string, then it's very easy to get that.

Just use the GetHashCode method.

Like this:

string hash = username.GetHashCode();
Cyril Gupta
Yes, that it what looking for. But it code is big mistake. Show write like int hash = "username".GetHasCode();
Edy Cu
Why have you put username in double quotes? That will get the hash of the word 'username' and now what's in the username variable.
Cyril Gupta