本文整理汇总了C#中System.Security.Cryptography.MD5CryptoServiceProvider.ComputeHash方法的典型用法代码示例。如果您正苦于以下问题:C# System.Security.Cryptography.MD5CryptoServiceProvider.ComputeHash方法的具体用法?C# System.Security.Cryptography.MD5CryptoServiceProvider.ComputeHash怎么用?C# System.Security.Cryptography.MD5CryptoServiceProvider.ComputeHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.MD5CryptoServiceProvider
的用法示例。
在下文中一共展示了System.Security.Cryptography.MD5CryptoServiceProvider.ComputeHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: ToMD5Bytes
public static byte[] ToMD5Bytes(this byte[] buffer)
{
var x = new System.Security.Cryptography.MD5CryptoServiceProvider();
return x.ComputeHash(buffer);
}
示例3: 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);
}
示例4: 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")));
}
示例5: 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;
}
示例6: 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;
}
示例7: GetMD5Hash
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
{
}
return (strResult);
}
示例8: 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 (), @"-", "");
}
示例9: 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);
}
示例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: 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;
}
示例12: CreateHash
public static string CreateHash(string unHashed)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(unHashed);
data = x.ComputeHash(data);
return System.Text.Encoding.ASCII.GetString(data);
}
示例13: CreateHash
/// <summary>
/// Hashes the entry string
/// </summary>
/// <param name="unhashed">The string not empty instance</param>
/// <returns>Hashed string</returns>
public static string CreateHash(this string unhashed)
{
if (string.IsNullOrWhiteSpace(unhashed))
return string.Empty;
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
return System.Text.Encoding.ASCII.GetString(md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(unhashed)));
}
示例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: GetMd5Str
/// <summary>
/// MD5 16位加密 加密后密码为大写
/// </summary>
/// <param name="ConvertString"></param>
/// <returns></returns>
public static string GetMd5Str(string ConvertString)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
t2 = t2.Replace("-", "");
return t2;
}