dl*****@gmail.com wrote:
Thank you for your reply, but I seem to be missing something. So far
what I understand is that when I convert it to a MD5 hash it generates
a byte array of the MD5 hash. I should be able to convert that byte
array into a string to view it
for example: MD5 hashing the string "C#" is
"d7efa19fbe7d3972fd5adb6024223d74".
No, actually, the MD5 hashing is the 128 bit binary data which, when
converted to a hexidecimal display, is the string you indicate. Basically
the hash (any hash) just generates some kind of binary data through a set of
mathematical operations on the underlying data that's being examined. For
example, it doesn't actually look at the text "C#" but at the binary
representation of that string, so a different encoding of C# (for example,
in UTF-16) will yield a different MD5 hash result.
Now it was suggested to convert the MD5 byte array into a base64
string which I can do, but that is a base64 string of the hash and
not really what I am looking for as I am looking for the MD5 hash in
a string format (like above and not in a base64 format)?
Actually, the base64 transformation turns a set of binary data into the
string representation you indicate above, so, in fact, it's exactly what you
want.
Playing around I found that
BitConverter.ToString( result ) ;
works in doing what I need done - but why doesn't
outputData = textConverter.GetString( result ) ;?
Because Text Converter attempts to transform a set of binary data into a
textual representation assuming a specific character code set. For example,
in ASCII, the 'A' character is (off the top of my head) 65 in decimal, and
41 in hexidecimal. So, conversely, the "39" in your string above, would
convert back to (again, off the top of my head) the ? symbol, at least with
the ASCII set (or a bunch of other sets which also map similarly). So,
thus, you get garbage in your translation.
To put it a different way, what you want is the hexidecimal representation
of your binary (byte) data, not the text representation of your binary data.
Thus, BitConverter and Base64 do what you want, but Text Converter does not.
Hope that helps.
--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]