J
John Puopolo
All:
I have a string that I need to encode using MD5. Since I am using C#,
my original, plain string is in Unicode, e.g."
string clearText = "foobar";
To use the MD5 hash function, I need to turn my string into a byte
array. However, I have choices:
// UTF8Encoding encoder = new UTF8Encoding();
// ASCIIEncoding encoder1 = new ASCIIEncoding();
// UnicodeEncoding encoder2 = new UnicodeEncoding();
// UTF7Encoding encoder3 = new UTF7Encoding();
// UTF8Encoding encoder4 = new UTF8Encoding();
// Convert given string to bytes required as input by MD5
// byte[] clearBytes1 = encoder1.GetBytes(clearText);
// byte[] clearBytes2 = encoder2.GetBytes(clearText);
// byte[] clearBytes3 = encoder3.GetBytes(clearText);
// byte[] clearBytes4 = encoder4.GetBytes(clearText);
A simple text shows that these conversions all do slightly different
things, thus the subsequent hash returns different values. Is there a
"right" one to choose to do a "standard" MD5 hash?
Thanks,
John
I have a string that I need to encode using MD5. Since I am using C#,
my original, plain string is in Unicode, e.g."
string clearText = "foobar";
To use the MD5 hash function, I need to turn my string into a byte
array. However, I have choices:
// UTF8Encoding encoder = new UTF8Encoding();
// ASCIIEncoding encoder1 = new ASCIIEncoding();
// UnicodeEncoding encoder2 = new UnicodeEncoding();
// UTF7Encoding encoder3 = new UTF7Encoding();
// UTF8Encoding encoder4 = new UTF8Encoding();
// Convert given string to bytes required as input by MD5
// byte[] clearBytes1 = encoder1.GetBytes(clearText);
// byte[] clearBytes2 = encoder2.GetBytes(clearText);
// byte[] clearBytes3 = encoder3.GetBytes(clearText);
// byte[] clearBytes4 = encoder4.GetBytes(clearText);
A simple text shows that these conversions all do slightly different
things, thus the subsequent hash returns different values. Is there a
"right" one to choose to do a "standard" MD5 hash?
Thanks,
John