MD5 and SHA1
//MD5
public static string MD5(string str) {
byte[] bytes=Encoding.Default.GetBytes(str);
bytes=MD5CryptoServiceProvider.computeHash(bytes);
string text="";
for(int i=0;i<bytes.Length;i++)
{
text=text+bytes[i].ToString("x").PadLeft(2,'0');
}
return text;
}
SHA1
public string SHA1_Encrypt(string Source_String) {
byte[] StrRes = Encoding.Default.GetBytes(Source_String);
HashAlgorithm iSHA=new SHA1CryptoServiceProvider();
StrRes = iSHA.ComputeHash(StrRes);
StringBuilder EnText = new StringBuilder();
foreach (byte iByte in StrRes)
{ EnText.AppendFormat("{0:x2}", iByte); }
return EnText.ToString();
}
浙公网安备 33010602011771号