Code Snippet - MD5 Encryption in C#
private string encryptString(string strToEncrypt)
{
System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
byte[] bytes = ue.GetBytes(strToEncrypt);
// encrypt bytes
System.Security.Cryptography.MD5CryptoServiceProvi der md5 = new
System.Security.Cryptography.MD5CryptoServiceProvi der();
byte[] hashBytes = md5.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
string hashString = "";
for(int i=0;i {
hashString += Convert.ToString(hashBytes[i],16).PadLeft(2,'0');
}
return hashString.PadLeft(32,'0');
}
{
System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
byte[] bytes = ue.GetBytes(strToEncrypt);
// encrypt bytes
System.Security.Cryptography
System.Security.Cryptography
byte[] hashBytes = md5.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
string hashString = "";
for(int i=0;i
hashString += Convert.ToString(hashBytes[i],16).PadLeft(2,'0
}
return hashString.PadLeft(32,'0');
}
0 Comments:
Post a Comment
<< Home