C# MD5 加密
2011-09-25 12:56
295 查看
using System;
using System.Drawing;
using System.Security.Cryptography;
using System.Windows.Forms;
namespace WinFormMD5
{
public partial class FormMD5 : Form
{
private MD5CryptoServiceProvider md5Hash;
private MaskedTextBox maskedText;
private TextBox textMD5;
public FormMD5()
{
InitializeComponent();
md5Hash = new MD5CryptoServiceProvider();
maskedText = new MaskedTextBox();
maskedText.Dock = DockStyle.Top;
maskedText.TextAlign = HorizontalAlignment.Center;
maskedText.ShortcutsEnabled = true;
maskedText.KeyDown += new KeyEventHandler(maskedText_KeyDown);
this.Controls.Add(maskedText);
textMD5 = new TextBox();
textMD5.Dock = DockStyle.Bottom;
textMD5.TextAlign = HorizontalAlignment.Center;
textMD5.ReadOnly = true;
textMD5.ShortcutsEnabled = true;
this.Controls.Add(textMD5);
this.HelpButton = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.AutoScaleMode = AutoScaleMode.Font; // 根据字体的维度控制缩放。
this.Font = new Font(Font.Name, 12F);
this.ClientSize = new Size(192, 52);
this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
}
private void maskedText_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Enter:
byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(maskedText.Text);
pwdBytes = md5Hash.ComputeHash(pwdBytes);
textMD5.Text = Convert.ToBase64String(pwdBytes).TrimEnd('='); // 无值字符“=”用于尾部的空白。
break;
case (Keys.Control | Keys.L):
maskedText.TextAlign = HorizontalAlignment.Left; // 文本居左。
break;
case (Keys.Control | Keys.E):
maskedText.TextAlign = HorizontalAlignment.Center; // 文本居中。
break;
case (Keys.Control | Keys.R):
maskedText.TextAlign = HorizontalAlignment.Right; // 文本居右。
break;
}
}
protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
{
base.OnHelpButtonClicked(e);
e.Cancel = true;
using (FontDialog fontDialog = new FontDialog())
{
fontDialog.Font = this.Font;
fontDialog.ShowEffects = false;
if (fontDialog.ShowDialog(this) == DialogResult.OK)
{
this.Font = fontDialog.Font;
int sw = TextRenderer.MeasureText(textMD5.Text, this.Font).Width;
this.ClientSize = new Size(sw, maskedText.Height + textMD5.Height);
Size ws = Screen.GetWorkingArea(this).Size - this.Size;
this.DesktopLocation = new Point(ws.Width / 2, ws.Height / 2);
}
}
}
}
}
using System.Drawing;
using System.Security.Cryptography;
using System.Windows.Forms;
namespace WinFormMD5
{
public partial class FormMD5 : Form
{
private MD5CryptoServiceProvider md5Hash;
private MaskedTextBox maskedText;
private TextBox textMD5;
public FormMD5()
{
InitializeComponent();
md5Hash = new MD5CryptoServiceProvider();
maskedText = new MaskedTextBox();
maskedText.Dock = DockStyle.Top;
maskedText.TextAlign = HorizontalAlignment.Center;
maskedText.ShortcutsEnabled = true;
maskedText.KeyDown += new KeyEventHandler(maskedText_KeyDown);
this.Controls.Add(maskedText);
textMD5 = new TextBox();
textMD5.Dock = DockStyle.Bottom;
textMD5.TextAlign = HorizontalAlignment.Center;
textMD5.ReadOnly = true;
textMD5.ShortcutsEnabled = true;
this.Controls.Add(textMD5);
this.HelpButton = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.AutoScaleMode = AutoScaleMode.Font; // 根据字体的维度控制缩放。
this.Font = new Font(Font.Name, 12F);
this.ClientSize = new Size(192, 52);
this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
}
private void maskedText_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Enter:
byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(maskedText.Text);
pwdBytes = md5Hash.ComputeHash(pwdBytes);
textMD5.Text = Convert.ToBase64String(pwdBytes).TrimEnd('='); // 无值字符“=”用于尾部的空白。
break;
case (Keys.Control | Keys.L):
maskedText.TextAlign = HorizontalAlignment.Left; // 文本居左。
break;
case (Keys.Control | Keys.E):
maskedText.TextAlign = HorizontalAlignment.Center; // 文本居中。
break;
case (Keys.Control | Keys.R):
maskedText.TextAlign = HorizontalAlignment.Right; // 文本居右。
break;
}
}
protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
{
base.OnHelpButtonClicked(e);
e.Cancel = true;
using (FontDialog fontDialog = new FontDialog())
{
fontDialog.Font = this.Font;
fontDialog.ShowEffects = false;
if (fontDialog.ShowDialog(this) == DialogResult.OK)
{
this.Font = fontDialog.Font;
int sw = TextRenderer.MeasureText(textMD5.Text, this.Font).Width;
this.ClientSize = new Size(sw, maskedText.Height + textMD5.Height);
Size ws = Screen.GetWorkingArea(this).Size - this.Size;
this.DesktopLocation = new Point(ws.Width / 2, ws.Height / 2);
}
}
}
}
}
相关文章推荐
- c#中MD5的加密解密
- C#MD5为密码加密
- C# MD5 加密
- C# MD5-16位加密实例,32位加密实例
- MD5等加密类 C#算法实现
- C# MD5 32位加密 UTF-8编码
- C#之MD5加密!...
- [C#] - MD5 加密的具体流程
- C# MD5 16位加密实例
- C# MD5 HASH的加密
- c# MD5盐值加密
- 使用C# 用MD5进行密码加密源代码
- C# MD5 加密方法 16位或32位
- C# MD5 32位加密 UTF-8编码
- c# MD5的加密和解密
- c#加密 可逆与不可逆MD5 加密
- C#:Md5和Sha1两种加密方式
- C# 加密-MD5 和 SHA1
- C#中Md5给密码加密
- C#中 MD5和SHA1加密代码