本文整理汇总了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类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:PolarbearDK,项目名称:Miracle.FileZilla.Api,代码行数:7,代码来源:Authentication.cs
示例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);
}
开发者ID:songques,项目名称:CSSIM_Solution,代码行数:34,代码来源:Hasher.cs
示例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;
}
开发者ID:ZGHhaswell,项目名称:AutoPublishDemo,代码行数:30,代码来源:MD5Utils.cs
示例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);
}
开发者ID:kora-hacker,项目名称:csharp_study_projects,代码行数:7,代码来源:Program.cs
示例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();
}
开发者ID:jsakamoto,项目名称:bjd5,代码行数:36,代码来源:Md5.cs
示例6: ToMD5Bytes
public static byte[] ToMD5Bytes(this byte[] buffer)
{
var x = new System.Security.Cryptography.MD5CryptoServiceProvider();
return x.ComputeHash(buffer);
}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:7,代码来源:CryptographyExtensions.cs
示例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);
}
开发者ID:3guy,项目名称:testRe,代码行数:7,代码来源:Md5Helper.cs
示例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")));
}
开发者ID:kkrnt,项目名称:Brute,代码行数:7,代码来源:Program.cs
示例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;
}
开发者ID:htphongqn,项目名称:esell.yeuthietkeweb.com,代码行数:7,代码来源:clsFormat.cs
示例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 );
}
开发者ID:sergey-msu,项目名称:nfx,代码行数:34,代码来源:NetworkUtils.cs
示例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;
}
开发者ID:aocakli,项目名称:mikrotik4net,代码行数:27,代码来源:ApiConnectorHelper.cs
示例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 (), @"-", "");
}
开发者ID:mdsdeveloper,项目名称:VeterinaryManager,代码行数:7,代码来源:Util.cs
示例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);
}
开发者ID:atom0s,项目名称:Campah,代码行数:28,代码来源:Updater.xaml.cs
示例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"));
}
开发者ID:wulab,项目名称:prototype.net,代码行数:7,代码来源:GravatarHelpers.cs
示例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);
}
开发者ID:wgang10,项目名称:ZYWeb,代码行数:25,代码来源:GetFileMD5.ashx.cs
示例16: 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;
}
开发者ID:chanhan,项目名称:ap_follow,代码行数:12,代码来源:StringHelper.cs
示例17: ComputeXCode
public static string ComputeXCode(object o, string token)
{
var strs = ComputeSourceKey(o, token);
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
var bys = md5.ComputeHash(Encoding.Unicode.GetBytes(strs));
return BitConverter.ToString(bys);
}
开发者ID:powerhai,项目名称:Jinchen,代码行数:7,代码来源:XCodeHelper.cs
示例18: 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;
}
catch ( System.Exception ex )
{
System.Windows.Forms.MessageBox.Show( ex.Message , "Error!" ,
System.Windows.Forms.MessageBoxButtons.OK ,
System.Windows.Forms.MessageBoxIcon.Error ,
System.Windows.Forms.MessageBoxDefaultButton.Button1 );
}
return ( strResult );
}
开发者ID:roboter,项目名称:FlashAutorun,代码行数:31,代码来源:ItemsEditor.cs
示例19: ToMd5Pass
public static string ToMd5Pass(this string value)
{
byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(ToByteArray(value));
string result = System.BitConverter.ToString(hash);
result = result.Replace("-", "");
return result;
}
开发者ID:cemkurtulus,项目名称:Project_Operation,代码行数:7,代码来源:Extensions.cs
示例20: 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);
}
开发者ID:kaungmyat,项目名称:university_stationary,代码行数:7,代码来源:EmpTracking.cs
注:本文中的System.Security.Cryptography.MD5CryptoServiceProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论