Converting to Hex

G

Guest

I have the following custom class that takes a string and generate an MD5
hash then to hexidecimal. I can not figure out how to convert MD5hash into
hex:

public static byte[] MD5Encryption(string ToEncrypt)
{
// Create instance of the crypto provider.
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
// Create a Byte array to store the encryption to return.
byte[] hashedbytes;
// Required UTF8 Encoding used to encode the input value to a usable state.
UTF8Encoding textencoder = new UTF8Encoding();

hashedbytes = md5.ComputeHash(textencoder.GetBytes(ToEncrypt));

StringBuilder sb = new StringBuilder();

for (int i=0;i<hashedbytes.Length;i++)
sb.Append(hashedbytes.ToString("x").PadLeft(2,'0'));



// Destroy objects that aren't needed.
md5.Clear();
md5 = null;

// return the hased bytes to the calling method.
return sb.ToString();
}

Any help would be greatly appreciated.

Thanks, Justin.
 
G

Guest

I guess I should probably explain my problem a little clearer. I have a
concantinated string of strings that I need to send to my credit card
processor but before I send it, it needs to be encrypted using the MD5
algorithm, I have managed to accomplish that. Now I need to convert the MD5
hash which is in byte[] format to hexidecimal format, I have no idea how to
do that.

Thanks, Justin.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top