Stanimir Stoyanov wrote:
Hi Miguel,
byte[] is an array and ToString() will just return the type name. Here
are a few examples:
1) return BitConverter.ToString(hash); // e.g. A1-F3-BB...
2) return BitConverter.ToString(hash).Replace("-", ""); // e.g. A1F3BB...
3) string hashString = string.Empty;
Array.ForEach(hash, delegate(byte b) { hashString +=
b.ToString("X2"); });
return hashString; // same as 2)
Don't use += to concatenate strings in a loop. Use a StringBuilder instead:
StringBuilder builder = new StringBuilder(hash.Length * 2);
foreach (byte b in hash) builder.Append(b.ToString("x2"));
return builder.ToString();
As the size of the final string is specified in the constructor, it will
allocate a string buffer of the correct size, which then is returned as
a string by the ToString method. (To make it ever more efficient, you
could format the hex string yourself and append one character at a time.
That way it wouldn't create any temporary strings at all.)
4) return Convert.ToBase64String(hash); // e.g. dh1e5gxs4hh3j...
--
Stanimir Stoyanov
http://stoyanoff.info
--
Göran Andersson
_____
http://www.guffa.com