本文整理汇总了C#中System.Security.Cryptography.MD5CryptoServiceProvider类的典型用法代码示例。如果您正苦于以下问题:C# System.Security.Cryptography.MD5CryptoServiceProvider类的具体用法?C# System.Security.Cryptography.MD5CryptoServiceProvider怎么用?C# System.Security.Cryptography.MD5CryptoServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Security.Cryptography.MD5CryptoServiceProvider类属于命名空间,在下文中一共展示了System.Security.Cryptography.MD5CryptoServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HashPassword
internal byte[] HashPassword(string password)
{
var cryptoServiceProvider = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] dataToHash = _nonce1.Concat(Encoding.UTF8.GetBytes(password)).Concat(_nonce2).ToArray();
var hash = cryptoServiceProvider.ComputeHash(dataToHash);
return hash;
}
示例2: GetMD5Hash
/// <summary>
/// 获得字节数组MD5值
/// </summary>
/// <param name="data">字节数组</param>
/// <returns>返回MD5值</returns>
public static string GetMD5Hash(byte[] data)
{
string strResult = "";
string strHashData = "";
byte[] arrbytHashValue;
System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher =
new System.Security.Cryptography.MD5CryptoServiceProvider();
try
{
arrbytHashValue = oMD5Hasher.ComputeHash(data);
strHashData = System.BitConverter.ToString(arrbytHashValue);
strHashData = strHashData.Replace("-", "");
strResult = strHashData;
}
catch
{
//System.Windows.Forms.MessageBox.Show(ex.Message, "Error!",System.Exception ex
// System.Windows.Forms.MessageBoxButtons.OK,
// System.Windows.Forms.MessageBoxIcon.Error,
// System.Windows.Forms.MessageBoxDefaultButton.Button1);
}
return (strResult);
}
示例3: GetMD5
public static string GetMD5(string filePath)
{
string strResult = "";
string strHashData = "";
byte[] arrbytHashValue;
System.IO.FileStream oFileStream = null;
System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher =
new System.Security.Cryptography.MD5CryptoServiceProvider();
try
{
oFileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);//计算指定Stream 对象的哈希值
oFileStream.Close();
//由以连字符分隔的十六进制对构成的String,其中每一对表示value 中对应的元素;例如“F-2C-4A”
strHashData = System.BitConverter.ToString(arrbytHashValue);
//替换-
strHashData = strHashData.Replace("-", "");
strResult = strHashData;
}
catch (System.Exception ex)
{
}
return strResult;
}
示例4: Main
static void Main(string[] args)
{
string test = "admin";
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] test_encrypt = System.Text.Encoding.ASCII.GetBytes(test);
byte[] result = md5.ComputeHash(test_encrypt);
}
示例5: Hash
//MD5によるハッシュ作成
public static string Hash(string passStr,string timestampStr)
{
const int range = 64;
var pass = Encoding.ASCII.GetBytes(passStr);
var timestamp = Encoding.ASCII.GetBytes(timestampStr);
var h = new System.Security.Cryptography.MD5CryptoServiceProvider();
var k = new byte[range];
if (range < pass.Length)
throw new InvalidOperationException("key length is too long");
var ipad = new byte[range];
var opad = new byte[range];
pass.CopyTo(k,0);
for (var i = pass.Length; i < range; i++) {
k[i] = 0x00;
}
for (var i = 0; i < range; i++) {
ipad[i] = (byte)(k[i] ^ 0x36);
opad[i] = (byte)(k[i] ^ 0x5c);
}
var hi = new byte[ipad.Length + timestamp.Length];
ipad.CopyTo(hi,0);
timestamp.CopyTo(hi,ipad.Length);
var hash = h.ComputeHash(hi);
var ho = new byte[opad.Length + hash.Length];
opad.CopyTo(ho,0);
hash.CopyTo(ho,opad.Length);
h.Initialize();
var tmp = h.ComputeHash(ho);
var sb = new StringBuilder();
foreach (var b in tmp) {
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
示例6: ToMD5Bytes
public static byte[] ToMD5Bytes(this byte[] buffer)
{
var x = new System.Security.Cryptography.MD5CryptoServiceProvider();
return x.ComputeHash(buffer);
}
示例7: GetMd5
public static string GetMd5(string str)
{
System.Security.Cryptography.MD5CryptoServiceProvider Md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] src = System.Text.Encoding.ASCII.GetBytes(str);
byte[] md5out=Md5.ComputeHash(src);
return Convert.ToBase64String(md5out);
}
示例8: MD5
public string MD5(string str)
{
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
var bs = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str));
md5.Clear();
return bs.Aggregate("", (current, b) => current + (b.ToString("x2")));
}
示例9: MaHoaMatKhau
public string MaHoaMatKhau(string Password)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hashedDataBytes = md5Hasher.ComputeHash(System.Text.UTF8Encoding.UTF8.GetBytes(Password));
string EncryptPass = Convert.ToBase64String(hashedDataBytes);
return EncryptPass;
}
示例10: GetMachineUniqueMACSignature
/// <summary>
/// Gets a string which represents a unique signature of this machine based on MAC addresses of interfaces.
/// The signature has a form of: [intf.count]-[CRC32 of all MACs]-[convoluted MD5 of all MACs]
/// </summary>
public static string GetMachineUniqueMACSignature()
{
var nics = NetworkInterface.GetAllNetworkInterfaces();
var buf = new byte[6 * 32];
var ibuf = 0;
var cnt=0;
var csum = new NFX.IO.ErrorHandling.CRC32();
foreach(var nic in nics.Where(a => a.NetworkInterfaceType!=NetworkInterfaceType.Loopback))
{
var mac = nic.GetPhysicalAddress().GetAddressBytes();
csum.Add( mac );
for(var i=0; i<mac.Length; i++)
{
buf[ibuf] = mac[i];
ibuf++;
if(ibuf==buf.Length) ibuf = 0;
}
cnt++;
}
var md5s = new StringBuilder();
using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
{
var hash = md5.ComputeHash(buf);
for(var i=0 ; i<hash.Length ; i+=2)
md5s.Append( (hash[i]^hash[i+1]).ToString("X2"));
}
return "{0}-{1}-{2}".Args( cnt, csum.Value.ToString("X8"), md5s );
}
示例11: EncodePassword
internal static string EncodePassword(string password, string hash)
{
byte[] hash_byte = new byte[hash.Length / 2];
for (int i = 0; i <= hash.Length - 2; i += 2)
{
hash_byte[i / 2] = Byte.Parse(hash.Substring(i, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture);
}
byte[] heslo = new byte[1 + password.Length + hash_byte.Length];
heslo[0] = 0;
Encoding.ASCII.GetBytes(password.ToCharArray()).CopyTo(heslo, 1);
hash_byte.CopyTo(heslo, 1 + password.Length);
Byte[] hotovo;
System.Security.Cryptography.MD5 md5;
md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
hotovo = md5.ComputeHash(heslo);
//Convert encoded bytes back to a 'readable' string
string result = "";
foreach (byte h in hotovo)
{
result += h.ToString("x2", CultureInfo.InvariantCulture);
}
return result;
}
示例12: GetEncondeMD5
public static string GetEncondeMD5(string password)
{
System.Security.Cryptography.MD5 md5;
md5 = new System.Security.Cryptography.MD5CryptoServiceProvider ();
Byte[] encodedBytes = md5.ComputeHash (ASCIIEncoding.Default.GetBytes (password));
return System.Text.RegularExpressions.Regex.Replace (BitConverter.ToString (encodedBytes).ToLower (), @"-", "");
}
示例13: GetMD5Hash
public static string GetMD5Hash(string pathName)
{
string strResult = "";
string strHashData = "";
byte[] arrbytHashValue;
System.IO.FileStream oFileStream = null;
System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher =
new System.Security.Cryptography.MD5CryptoServiceProvider();
try
{
oFileStream = GetFileStream(pathName);
arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);
oFileStream.Close();
strHashData = System.BitConverter.ToString(arrbytHashValue);
strHashData = strHashData.Replace("-", "");
strResult = strHashData;
oMD5Hasher.Clear();
}
catch (System.Exception)
{
oMD5Hasher.Clear();
}
return (strResult);
}
示例14: MD5
private static string MD5(string theEmail)
{
var md5Obj = new System.Security.Cryptography.MD5CryptoServiceProvider();
var bytesToHash = Encoding.ASCII.GetBytes(theEmail);
bytesToHash = md5Obj.ComputeHash(bytesToHash);
return bytesToHash.Aggregate("", (current, b) => current + b.ToString("x2"));
}
示例15: ProcessRequest
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string md5Code = "NoUpdate";
try
{
string fileName = context.Request.QueryString["FileName"];
string filePath = context.Server.MapPath("App/Update/"+fileName);
if (File.Exists(filePath))
{
FileStream file = new FileStream(filePath, FileMode.Open);
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
md5Code = sb.ToString();
}
}
catch { }
context.Response.Write(md5Code);
}