Home All Groups Group Topic Archive Search About
Author
11 Aug 2005 4:24 AM
Alfredo
Hi,

I have many questions.

1. I need to create a Hash value of a String. Does anybody has a
function? I am havin troubles doing my own function, because i fail
converting a Byte() to a String.

2. What is the most security algorithm? MD5, SHA1, SHA512??

3. What is the difference bettewn Dim x as byte() and Dim x() as Byte

4. I debug my own function, i am getting surprise when i enter a long
string like 500 characters, and ComputeHash return me a string of 35
characters!! I think i am doing something wrong here.

Thanks

Alfredo Barrientos

Author
11 Aug 2005 3:41 PM
William Stacey [MVP]
> 1. I need to create a Hash value of a String. Does anybody has a
> function? I am havin troubles doing my own function, because i fail
> converting a Byte() to a String.

        private void button1_Click(object sender, EventArgs e)
        {
            string s = "My string to hash.";
            byte[] ba = Encoding.UTF8.GetBytes(s);

            byte[] md5Hash = MD5.Create().ComputeHash(ba);
            string base64Hash = Convert.ToBase64String(md5Hash);
            Console.WriteLine("MD5 hash of string is:" + base64Hash);
            Console.WriteLine("MD5 hash length in bytes:" + md5Hash.Length);

            byte[] sha1Hash = SHA1.Create().ComputeHash(ba);
            base64Hash = Convert.ToBase64String(sha1Hash);
            Console.WriteLine("SHA1 hash of string is:" + base64Hash);
            Console.WriteLine("SHA1 hash length in bytes:"+
sha1Hash.Length);

            byte[] sha256Hash = SHA256.Create().ComputeHash(ba);
            base64Hash = Convert.ToBase64String(sha256Hash);
            Console.WriteLine("SHA256 hash of string is:" + base64Hash);
            Console.WriteLine("SHA256 hash length in bytes:" +
sha256Hash.Length);
        }

// Output:
MD5 hash of string is:DS4DrhUB33YBfoK8S7PJ6g==
MD5 hash length in bytes:16
SHA1 hash of string is:TNH/hNKWZKVDK5/RbTgD+9c4lQg=
SHA1 hash length in bytes:20
SHA256 hash of string is:M3GLzAsXhdtIF+pcZ/fWDD5rcfbDptb3RzkFdmM/0jE=
SHA256 hash length in bytes:32


> 2. What is the most security algorithm? MD5, SHA1, SHA512??

The strength of the hash follows the order you listed.

>
> 3. What is the difference bettewn Dim x as byte() and Dim x() as Byte
>
> 4. I debug my own function, i am getting surprise when i enter a long
> string like 500 characters, and ComputeHash return me a string of 35
> characters!! I think i am doing something wrong here.

As you see above, the hash is always the same size depending on the hash
algo you pick.  md5 is 16 bytes, sha1 is 20, sha256 is 32, etc.

--
William Stacey [MVP]
Author
11 Aug 2005 6:00 PM
Alfredo
Thank you very much William,

But, I dont understand how is possible to get a diferent hash value for
numbers from 1 to 1 000 000 000 000 000 000 000 000 000 000 000 000, if
my maximun combination is 1 00 000 000 000 000 000 000 000 000 000 000
- 1?

Thanks,

Alfredo Barrientos
Author
11 Aug 2005 11:12 PM
William Stacey [MVP]
The hash space is finite.  The data space that you might hash is infinite.
It follows there is an infinite number of hash collisions.

--
William Stacey [MVP]

Show quoteHide quote
"Alfredo" <abarrien***@gmail.com> wrote in message
news:1123783237.815413.285130@g47g2000cwa.googlegroups.com...
> Thank you very much William,
>
> But, I dont understand how is possible to get a diferent hash value for
> numbers from 1 to 1 000 000 000 000 000 000 000 000 000 000 000 000, if
> my maximun combination is 1 00 000 000 000 000 000 000 000 000 000 000
> - 1?
>
> Thanks,
>
> Alfredo Barrientos
>
Author
13 Aug 2005 6:10 PM
Dominick Baier [DevelopMentor]
Hello Alfredo,

hash algorithms (especially the more sophisticated ones) are complex beasts.
Grab a copy of Schneier "Applied Cryptography" if you want the details.

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> Thank you very much William,
>
> But, I dont understand how is possible to get a diferent hash value
> for numbers from 1 to 1 000 000 000 000 000 000 000 000 000 000 000
> 000, if my maximun combination is 1 00 000 000 000 000 000 000 000 000
> 000 000 - 1?
>
> Thanks,
>
> Alfredo Barrientos
>
Author
19 Aug 2005 3:04 PM
Alfredo
Thank you very much.

How many algorithms does .net support?

Thanks,

Alfredo Barrientos
Author
20 Aug 2005 7:08 AM
Dominick Baier [DevelopMentor]
Hello Alfredo,

http://www.leastprivilege.com/SupportedHashingAlgorithmsForPasswordDeriveBytes.aspx

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> Thank you very much.
>
> How many algorithms does .net support?
>
> Thanks,
>
> Alfredo Barrientos
>