当前位置: 首页>>代码示例>>C#>>正文


C# System.Security.Cryptography.MD5CryptoServiceProvider.ComputeHash方法代码示例

本文整理汇总了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();
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:36,代码来源:Md5.cs

示例2: 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

示例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);
 }
开发者ID:3guy,项目名称:testRe,代码行数:7,代码来源:Md5Helper.cs

示例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")));
 }
开发者ID:kkrnt,项目名称:Brute,代码行数:7,代码来源:Program.cs

示例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;
 }
开发者ID:htphongqn,项目名称:esell.yeuthietkeweb.com,代码行数:7,代码来源:clsFormat.cs

示例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;
        }
开发者ID:ZGHhaswell,项目名称:AutoPublishDemo,代码行数:30,代码来源:MD5Utils.cs

示例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);
        }
开发者ID:tomatochen,项目名称:jcshop,代码行数:25,代码来源:CHelper.cs

示例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 (), @"-", "");
 }
开发者ID:mdsdeveloper,项目名称:VeterinaryManager,代码行数:7,代码来源:Util.cs

示例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);
        }
开发者ID:songques,项目名称:CSSIM_Solution,代码行数:34,代码来源:Hasher.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: 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

示例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);
 }
开发者ID:kaungmyat,项目名称:university_stationary,代码行数:7,代码来源:EmpTracking.cs

示例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)));
 }
开发者ID:Mechtatel-student,项目名称:CS1_Project,代码行数:12,代码来源:User.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: 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


注:本文中的System.Security.Cryptography.MD5CryptoServiceProvider.ComputeHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。