private string getMD5String(string PlainText)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBuffer = System.Text.Encoding.ASCII.GetBytes(PlainText);
byte[] outputBuffer = md5.ComputeHash(inputBuffer);
//Convert the byte[] to a hex-string
System.Text.StringBuilder builder = new System.Text.StringBuilder (outputBuffer.Length);
for (int i = 0; i < outputBuffer.Length; i++)
{
builder.Append(outputBuffer[i].ToString("X2"));
}
return builder.ToString();
}
Refactorings
No refactoring yet !
GoodDoer
September 2, 2008, September 02, 2008 03:10, permalink
acidmind, you do know that this is a place where people post code snippets for others to refactor, right?
there are a few code-snippet-repositories where you can submit your code (if you feel you have to...)
David
October 19, 2008, October 19, 2008 09:20, permalink
refactored using linq syntax, removing unnecessary variables
private string CreateMD5String(string s) {
byte[] hashedBytes = MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(s));
return String.Join(String.Empty, hashedBytes.Select(b => b.ToString("x2")).ToArray());
}
This is a simple example of Cryptography Class using MD5 algorithm.
Remember... the MD5 don't have "Decrypt" method... it's only by comparison!!!