MD5 encryption applications under. Net

Source: Internet
Author: User
Tags md5 md5 encryption tostring

C # Usage /**////strings that need to be encrypted
///offset
///sdatain encrypted string
public string GetMD5 (string sdatain, string move)
... {
System.Security.Cryptography.MD5CryptoServiceProvider
MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider ();
byte[] Bytvalue, Bythash;
Bytvalue = System.Text.Encoding.UTF8.GetBytes (move + sdatain);
Bythash = Md5.computehash (Bytvalue);
MD5. Clear ();
String stemp = "";
for (int i = 0; i < bythash.length i++)
... {
Stemp + = Bythash[i]. ToString ("X"). PadLeft (2, ' 0 ');
}
return stemp
}
TextBox1.Text = this. GetMD5 ("123456", "");
Result: e10adc3949ba59abbe56e057f20f883e

Alternative Application C # usage/**//// 需要加密的字符串
/// 偏移量
/// sDataIn加密后的字符串
public string GetMD5(string sDataIn, string move)
...{
System.Security.Cryptography.MD5CryptoServiceProvider
md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytValue, bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(move + sDataIn);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
string sTemp = "";
for (int i = 0; i < bytHash.Length; i++)
...{
sTemp += bytHash[i].ToString("x").PadLeft(2, '0');
}
return sTemp;
}
textBox1.Text = this.GetMD5("123456","");
结果: e10adc3949ba59abbe56e057f20f883e

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.