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


C# MD5CryptoServiceProvider.ComputeHash方法代码示例

本文整理汇总了C#中MD5CryptoServiceProvider.ComputeHash方法的典型用法代码示例。如果您正苦于以下问题:C# MD5CryptoServiceProvider.ComputeHash方法的具体用法?C# MD5CryptoServiceProvider.ComputeHash怎么用?C# MD5CryptoServiceProvider.ComputeHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MD5CryptoServiceProvider的用法示例。


在下文中一共展示了MD5CryptoServiceProvider.ComputeHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMd5Sum

    public static string GetMd5Sum(string str)
    {
        // First we need to convert the string into bytes, which
        // means using a text encoder.
        Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

        // Create a buffer large enough to hold the string
        byte[] unicodeText = new byte[str.Length * 2];
        enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

        // Now that we have a byte array we can ask the CSP to hash it
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] result = md5.ComputeHash(unicodeText);

        // Build the final string by converting each byte
        // into hex and appending it to a StringBuilder
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < result.Length; i++)
        {
            sb.Append(result[i].ToString("X2"));
        }

        // And return it
        return sb.ToString();
    }
开发者ID:ali-codehoppers,项目名称:simplicity-forms-estate-agent,代码行数:25,代码来源:Utility.cs

示例2: btConfirm_Click

    /// <summary>
    /// 处理确定按钮点击事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btConfirm_Click(object sender, EventArgs e)
    {
        Admin admin = new Admin();

        MD5CryptoServiceProvider HashMD5 = new MD5CryptoServiceProvider();
        string oldPwd =
            ASCIIEncoding.ASCII.GetString(HashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tbOldPwd.Text)));
        string newPwd1 =
            ASCIIEncoding.ASCII.GetString(HashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tbNewPwd1.Text)));
        string newPwd2 =
            ASCIIEncoding.ASCII.GetString(HashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tdNewPwd2.Text)));

        if (admin.ChangePassword(Session["UserName"].ToString(), oldPwd, newPwd1, newPwd2))
        {
            //胡媛媛修改,修改跳转语句的位置,2010-01-15
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
                "<script>alert('修改成功!');window.location='./index.aspx'</script>");
            //Response.Redirect("./index.aspx");
            //胡媛媛修改,修改跳转语句的位置,2010-01-15
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
                "<script>alert('对不起,您修改密码失败,原因可能是您输入的原密码不正确或是两次输入的新密码不一致!')</script>");
        }
    }
开发者ID:dalinhuang,项目名称:my-project-step,代码行数:31,代码来源:Change_Admin_Password.aspx.cs

示例3: ComputeMD5

    public static string ComputeMD5(string value)
    {
        /*
         * Create the md5 crypt service provider
         */
        MD5 crypt = new MD5CryptoServiceProvider();
        StreamWriter pwd = new StreamWriter(new MemoryStream());
        pwd.Write(value);
        pwd.Flush();

        /*
         * Compute the hash code
         */
        pwd.BaseStream.Seek(0, SeekOrigin.Begin);
        byte[] cryptHash = crypt.ComputeHash(pwd.BaseStream);

        /*
         * Convert the result to hex
         */
        string result = "";

        int nLen = cryptHash.Length;
        for (int nPos = 0; nPos < nLen; nPos++)
        {
            byte cBuff = cryptHash[nPos];
            result += Convert((long)cBuff, 16);
        }

        return result.ToLower();
    }
开发者ID:kavallo,项目名称:E-Menu,代码行数:30,代码来源:MD5.cs

示例4: In

   public void In(
      [FriendlyName("Key", "The string to be used to generate the hash from.")]
      string Key,

      [FriendlyName("MD5 Hash", "The MD5 Hash generated by the Key.")]
      out string Hash
      )
   {
      if (Key != "")
      {
         UTF8Encoding ue = new UTF8Encoding();
         byte[] bytes = ue.GetBytes(Key);

         // encrypt bytes
         MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
         byte[] hashBytes = md5.ComputeHash(bytes);

         // Convert the encrypted bytes back to a string (base 16)
         string tmpHash = "";

         for (int i = 0; i < hashBytes.Length; i++)
         {
            tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
         }

         Hash = tmpHash.PadLeft(32, '0');
      }
      else
      {
         uScriptDebug.Log("[Generate MD5 Hash] The Key provided was empty, returning an empty string for the MD5 Hash.", uScriptDebug.Type.Warning);
         Hash = "";
      }

   }
开发者ID:Zyanede,项目名称:Own-Projects,代码行数:34,代码来源:uScriptAct_GenerateMD5Hash.cs

示例5: Encrypt

    public string Encrypt(string ToEncrypt, bool useHasing)
    {
        byte[] keyArray;
        byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(ToEncrypt);

        string Key = "malkit";
        if (useHasing)
        {
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(Key));
            hashmd5.Clear();
        }
        else
        {
            keyArray = UTF8Encoding.UTF8.GetBytes(Key);
        }
        TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
        tDes.Key = keyArray;
        tDes.Mode = CipherMode.ECB;
        tDes.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tDes.CreateEncryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
        tDes.Clear();
        return Convert.ToBase64String(resultArray, 0, resultArray.Length);
    }
开发者ID:riteshventurepact,项目名称:TAPD,代码行数:25,代码来源:EncryptDecrypt.cs

示例6: Decrypt

    public string Decrypt(string cypherString, bool useHasing)
    {
        byte[] keyArray;
        byte[] toDecryptArray = Convert.FromBase64String(cypherString.Replace(' ','+'));

        string key = "malkit";
        if (useHasing)
        {
            MD5CryptoServiceProvider hashmd = new MD5CryptoServiceProvider();
            keyArray = hashmd.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
            hashmd.Clear();
        }
        else
        {
            keyArray = UTF8Encoding.UTF8.GetBytes(key);
        }
        TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
        tDes.Key = keyArray;
        tDes.Mode = CipherMode.ECB;
        tDes.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tDes.CreateDecryptor();
        try
        {
            byte[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);
            tDes.Clear();
            return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
开发者ID:riteshventurepact,项目名称:TAPD,代码行数:32,代码来源:EncryptDecrypt.cs

示例7: MD5Encode

 /// <summary>
 /// MD5加密
 /// </summary>
 /// <param name="strOriginal"></param>
 /// <returns></returns>
 public static string MD5Encode(string strOriginal)
 {
     byte[] byteInput = UTF8Encoding.UTF8.GetBytes(strOriginal);
     MD5CryptoServiceProvider objMD5 = new MD5CryptoServiceProvider();
     byte[] byteOutput = objMD5.ComputeHash(byteInput);
     return BitConverter.ToString(byteOutput).Replace("-", "");
 }
开发者ID:chutinhha,项目名称:fixed-asset-system,代码行数:12,代码来源:EncodeHelper.cs

示例8: LogIn

    protected void LogIn(object sender, EventArgs e)
    {
        // Colecting data
        string email = TBEmail.Text;
        string password = TBPass.Text;

        // Hashing password
        MD5 md5 = new MD5CryptoServiceProvider();
        md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));
        password = Convert.ToBase64String(md5.Hash);

        // Checking login details
        Staff account = DBConnectivity.login(email, password);

        if (account != null)
        {
            // Loging OK
            Session["auth_email"] = account.email;
            Session["first_name"] = account.firstName;
            Session["access"] = account.access;
            Response.Redirect("~/Manage-Pets");
        }
        else
        {
            // Bad details
            ErrorMessage.Visible = true;
            FailureText.Text = "Bad credentials. Try again.";
        }
    }
开发者ID:knowbody,项目名称:fwp,代码行数:29,代码来源:Login.aspx.cs

示例9: md5method

 public static string md5method(string textoPlano)
 {
     byte[] data = System.Text.UTF8Encoding.ASCII.GetBytes(textoPlano);
     MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
     byte[] hashbyte = md5.ComputeHash(data, 0, data.Length);
     return BitConverter.ToString(hashbyte);
 }
开发者ID:jaratj87,项目名称:grn,代码行数:7,代码来源:Default.aspx.cs

示例10: encrypt

 public string encrypt(string strChange)
 {
     byte[] pass = Encoding.UTF8.GetBytes(strChange);
     MD5 md5 = new MD5CryptoServiceProvider();
     string strPassword = Encoding.UTF8.GetString(md5.ComputeHash(pass));
     return strPassword;
 }
开发者ID:adrianObel,项目名称:Care-Libro,代码行数:7,代码来源:Index.aspx.cs

示例11: Encrypt

    public static string Encrypt(string plainText )
    {
        string encrypted = null;
            try
            {
                byte[] inputBytes = ASCIIEncoding.ASCII.GetBytes(plainText);
                byte[] pwdhash = null;
                MD5CryptoServiceProvider hashmd5;

                //generate an MD5 hash from the password.
                //a hash is a one way encryption meaning once you generate
                //the hash, you cant derive the password back from it.
                hashmd5 = new MD5CryptoServiceProvider();
                pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
                hashmd5 = null;

                // Create a new TripleDES service provider
                TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
                tdesProvider.Key = pwdhash;
                tdesProvider.Mode = CipherMode.ECB;
                byte [] edata = tdesProvider.CreateEncryptor().TransformFinalBlock(inputBytes, 0, inputBytes.Length);
                encrypted = Convert.ToBase64String(	edata );

            }
            catch(Exception e)
            {
                string str = e.Message;
                throw ;
            }
            return encrypted;
    }
开发者ID:vibhutisuthar,项目名称:TEST,代码行数:31,代码来源:Tools.cs

示例12: Encrypt

    public static string Encrypt(string toEncrypt, bool useHashing)
    {
        byte[] keyArray;
        byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);
        System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
        string key = (string)settingsReader.GetValue("search", typeof(string));
        if (useHashing)
        {
            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
            hashmd5.Clear();
        }
        else
                    keyArray = UTF8Encoding.UTF8.GetBytes(key);

            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = keyArray;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;
            ICryptoTransform cTransform = tdes.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            tdes.Clear();
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);

        }   
开发者ID:gowrinath,项目名称:Public-Health-Care-System,代码行数:25,代码来源:encryption.cs

示例13: Com

    private static string Com(Stream stream)
    {
        MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

        md5.ComputeHash(stream);

        byte[] hash = md5.Hash;

        if (hash == null)
        {
            _ecode = MD5ErrorCode.E_ComputeHash;

            return string.Empty;
        }

        StringBuilder sb = new StringBuilder();

        foreach (byte byt in hash)
        {

            sb.Append(String.Format("{0:X1}", byt));

        }

        string ret = sb.ToString();

        sb = null;

        return ret; 

    }
开发者ID:seenen,项目名称:HerosTechBak_Seenen,代码行数:31,代码来源:MD5.cs

示例14: In

    public void In(
      [FriendlyName("Key", "The string to be used to check against the provided MD5 hash.")]
      string Key,
      
      [FriendlyName("MD5 Hash", "The MD5 Hash to check the key against.")]
      string Hash
      )
    {
        if (Key != "" && Hash != "")
          {
         UTF8Encoding ue = new UTF8Encoding();
         byte[] bytes = ue.GetBytes(Key);

         // encrypt bytes
         MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
         byte[] hashBytes = md5.ComputeHash(bytes);

         // Convert the encrypted bytes back to a string (base 16)
         string tmpHash = "";

         for (int i = 0; i < hashBytes.Length; i++)
         {
            tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
         }

         string finalHash = tmpHash.PadLeft(32, '0');

         if (finalHash == Hash)
         {
            m_GoodHash = true;
         }
          }
    }
开发者ID:Oxy949,项目名称:Obscended,代码行数:33,代码来源:uScriptAct_CheckMD5Hash.cs

示例15: GoodieTwoShoes

    public static string GoodieTwoShoes(string factora)
    {
        MD5 md5 = new MD5CryptoServiceProvider();

        string sResult = "";
        string sSecret = "jsdkfjks3423345879(*&*&&fdsdf903e38278sd";
        string sStringIn = factora + sSecret;

        char[] caData = sStringIn.ToCharArray();
        byte[] data = new byte[caData.GetLength(0)];
        int i = 0;
        foreach (char c in caData)
        {
            data[i++] = (byte)c;
        }

        byte[] result = md5.ComputeHash(data);

        string sTemp;
        foreach (byte b in result)
        {
            sTemp = b.ToString("x");

            if (sTemp.Length == 1)
            {
                sTemp = "0" + sTemp;
            }
            sResult = sResult + sTemp;
        }

        char[] szNum = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

        sResult = string.Format("{0}-{1}-{2}-{3}", sResult.Substring(3, 5), sResult.Substring(8, 5), sResult.Substring(16, 5), sResult.Substring(22, 5));
        return sResult.ToUpper();
    }
开发者ID:spamarti,项目名称:wwt-web-client,代码行数:35,代码来源:login.aspx.cs


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