乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      C#哈希Md5加密

       青格兒 2009-03-17
       
      public partial class HashEncrypt
          {
              /// <summary>
              /// </summary>
              /// <param name="strSource">待加密字串</param>
              /// <returns>加密后的字串</returns>
              public static string MD5Encrypt(string strSource)
              {
                  return MD5Encrypt(strSource, 16);
              }

              /// <summary>
              /// </summary>
              /// <param name="strSource">待加密字串</param>
              /// <param name="length">16或32值之一,其它則采用.net默認(rèn)MD5加密算法</param>
              /// <returns>加密后的字串</returns>
              public static string MD5Encrypt(string strSource, int length)
              {
                  byte[] bytes = Encoding.ASCII.GetBytes(strSource);
                  byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
                  StringBuilder sb = new StringBuilder();
                  switch (length)
                  {
                      case 16:
                          for (int i = 4; i < 12; i++)
                              sb.Append(hashValue[i].ToString("x2"));
                          break;
                      case 32:
                          for (int i = 0; i < 16; i++)
                          {
                              sb.Append(hashValue[i].ToString("x2"));
                          }
                          break;
                      default:
                          for (int i = 0; i < hashValue.Length; i++)
                          {
                              sb.Append(hashValue[i].ToString("x2"));
                          }
                          break;
                  }
                  return sb.ToString();
              }

              /// <summary>
              /// md5 encrypt
              /// </summary>
              /// <param name="str"></param>
              /// <returns></returns>
              public static string MSMD5(String str)
              {
                  MD5 md5 = new MD5CryptoServiceProvider();
                  byte[] data = System.Text.Encoding.Default.GetBytes(str);
                  byte[] result = md5.ComputeHash(data);
                  String ret = "";
                  for (int i = 0; i < result.Length; i++)
                      ret += result[i].ToString("x").PadLeft(2, '0');
                  return ret;
              }

              /// <summary>
              /// get md5 hash value
              /// </summary>
              /// <param name="input"></param>
              /// <returns></returns>
              static string MSGetMd5Hash(string input)
              {
                  // Create a new instance of the MD5CryptoServiceProvider object.
                  MD5 md5Hasher = System.Security.Cryptography.MD5.Create();
                  // Convert the input string to a byte array and compute the hash.
                  byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
                  // Create a new Stringbuilder to collect the bytes
                  // and create a string.
                  StringBuilder sBuilder = new StringBuilder();
                  // Loop through each byte of the hashed data
                  // and format each one as a hexadecimal string.
                  for (int i = 0; i < data.Length; i++)
                  {
                      sBuilder.Append(data[i].ToString("x2"));
                  }
                  // Return the hexadecimal string.
                  return sBuilder.ToString();
              }

              /// <summary>
              /// Verify a hash against a string.
              /// </summary>
              /// <param name="input"></param>
              /// <param name="hash"></param>
              /// <returns></returns>
              static bool VerifyMd5Hash(string input, string hash)
              {
                  // Hash the input.
                  string hashOfInput = MSGetMd5Hash(input);
                  // Create a StringComparer an comare the hashes.
                  StringComparer comparer = StringComparer.OrdinalIgnoreCase;
                  if (0 == comparer.Compare(hashOfInput, hash))
                  {
                      return true;
                  }
                  else
                  {
                      return false;
                  }
              }
          }

      MD5是單向加密的,嗯 ,可逆加密怎么做呢?嗯 ,這里收藏一個(gè)不錯(cuò)的文章,總結(jié)得挺全。共兩部分,感謝興趣的自己看吧。
       
      嗯 ,急著用的話,可以看這里,這個(gè)簡單好懂
       
       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約