[newbie] Formatting hash

G

Guest

Hi

In my program I once want to print a MD5- Hash I created to the user. But how can I convert this byte array to a human readable string, so that it looks like e.g.: 0d89c9f9834b3 etc.. Can anyone point this out

Thanks a lo
John
 
A

Ayende Rahien

John said:
Hi,

In my program I once want to print a MD5- Hash I created to the user. But how can I convert this byte array to a human readable string, so that it looks like e.g.: 0d89c9f9834b3 etc.. Can anyone point this out?

Thanks a lot
John

System.Text.Encoding.ASCII.GetString()
 
G

Guest

Yeah, but that just gives me the ASCII representation of my string, and not a hex dump. Any ideas

John
 
C

cody

Yeah, but that just gives me the ASCII representation of my string, and
not a hex dump. Any ideas?


array.ToString("x");

Could work (not tested). If not, you have to convert every single byte to a
hexstring using myint.ToString("x2");
 
J

Jon Skeet [C# MVP]

John Fisher said:
In my program I once want to print a MD5- Hash I created to the user.
But how can I convert this byte array to a human readable string, so
that it looks like e.g.: 0d89c9f9834b3 etc.. Can anyone point this
out?

Have a look at Convert.ToString(byte[]). That will give a human
readable version, although not quite in the form you specified. Using
String.ToLower and String.Replace will get you to your example format
if you really want it though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top