zoukankan      html  css  js  c++  java
  • MD5计算器

    private void radioBtnFlie_CheckedChanged(object sender, EventArgs e)
    {
        RadioButton rb = sender as RadioButton;
        if (rb != null)
        {
            if (rb.Checked)
                lblTip.Text = "文件:";
            else
                lblTip.Text = "字符串:";
        }
    }
    RadioButton切换
    private void txtStr_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {//拖进来的是文件
            e.Effect = DragDropEffects.Link;
            txtStr.Cursor = Cursors.Arrow;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }
    private void txtStr_DragDrop(object sender, DragEventArgs e)
    {
        string value = (e.Data.GetData(DataFormats.FileDrop) as System.Array).GetValue(0).ToString();
        txtStr.Cursor = Cursors.IBeam;
        txtStr.Text = value;
        //文件转MD5
        StringBuilder sbResult = new StringBuilder();
        using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
        {
            byte[] byteArr = File.ReadAllBytes(value);
            byte[] bytes = md5.ComputeHash(byteArr);
            for (int i = 0; i < bytes.Length; i++)
            {
                sbResult.Append(bytes[i].ToString("x2"));
            }
        }
        txtMD5.Text = sbResult.ToString();
    }
    鼠标拖动文件到第一个大文本框触发事件-将文件转换为MD5
    private void txtStr_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 'x1')
        {//Ctrl+A-全选
            (sender as TextBox).SelectAll();
            e.Handled = true;
        }
    }
    第一个大文本框Ctrl+A全选
    private void txtStr_KeyUp(object sender, KeyEventArgs e)
    {
        string str = txtStr.Text;
        if (str.Length > 0 && radioBtnString.Checked)
        {
            //字符串转MD5
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
            {
                byte[] md5Bytes = md5.ComputeHash(bytes);
                StringBuilder sbResult = new StringBuilder();
                for (int i = 0; i < md5Bytes.Length; i++)
                {
                    //十六进制占两位
                    sbResult.Append(md5Bytes[i].ToString("x2"));
                }
                txtMD5.Text = sbResult.ToString();
            }
        }
    }
    第一个大文本框按键松开后的事件(Ctrl+V或输入字符串)
    private void btnCompare_Click(object sender, EventArgs e)
    {
        //比较MD5值
        string text1 = txtMD5.Text.Trim();
        string text2 = txtRefer.Text.Trim();
        if (text1 == text2 && text1.Length > 0)
        {
            MessageBox.Show("MD5值相同");
        }
        else
        {
            MessageBox.Show("MD5值不相同");
        }
    }
    按钮比较MD5事件
  • 相关阅读:
    NGUI的sprite的使用(九宫切图)
    NGUI的button的创建的问题(Button Script)
    NGUI的Lebal需注意问题
    untiy3D-初学NGUI遇到问题
    MVC路由学习:自定义路由参数(用户看不到参数名),重新定义路由规则
    C#设计模式:工厂模式
    C#设计模式:抽象工厂(Abstract Factory)
    2014年计算机求职总结--准备篇
    UVA OJ 10035
    UVa OJ 455 Periodic Strings
  • 原文地址:https://www.cnblogs.com/zhyue93/p/MD51.html
Copyright © 2011-2022 走看看