.net下的MD5加密应用 .net开发
关键字:
C#用法
/**//// <param name="sDataIn">需要加密的字符串</param>
/// <param name="move">偏移量</param>
/// <returns>sDataIn加密后的字符串</returns>
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
/**//// <param name="sDataIn">需要加密的字符串</param>
/// <param name="move">偏移量</param>
/// <returns>sDataIn加密后的字符串</returns>
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
C#用法
/**//// <param name="sDataIn">需要加密的字符串</param>
/// <param name="move">偏移量</param>
/// <returns>sDataIn加密后的字符串</returns>
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
/**//// <param name="sDataIn">需要加密的字符串</param>
/// <param name="move">偏移量</param>
/// <returns>sDataIn加密后的字符串</returns>
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
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/