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.
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.