MD5计算器
Posted zhyue93
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = "字符串:"; } }
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(); }
private void txtStr_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == \'\\x1\') {//Ctrl+A-全选 (sender as TextBox).SelectAll(); e.Handled = true; } }
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(); } } }
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计算器的主要内容,如果未能解决你的问题,请参考以下文章