看了张子阳的博客,自己也看了一些资料,于是动手写了一个对文件加密与机密的小玩意,贴出来供大家参考,呵呵,可能对于高手来说,这个东西显的十分粗糙,希望大侠能够指点一二。
首先是程序的运行界面。

在该程序中自己写了一个类CryptoHelper,用来实现对文件的加密与解密操作。下面是这个类的源代码。
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Security.Cryptography;
- using System.IO;
- namespace PassWord
- {
- class CryptoHelper
- {
- private SymmetricAlgorithm provider;
- private ICryptoTransform encryptor;
- private ICryptoTransform decryptor;
- private const int per_length = 100;
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static int [] GetKeyLength(string algrorithmName)
- {
- int[] Int_Key = new int[4] { 0,0,0,0};
- switch (algrorithmName)
- {
- case "DES":
- {
- Int_Key[0] = 64;
- Int_Key[1] = 0;
- Int_Key[2] = 0;
- Int_Key[3] = 0;
- return Int_Key;
- }
- case "RC2":
- {
- Int_Key[0] = 40;
- Int_Key[1] = 128;
- Int_Key[2] = 8;
- Int_Key[3] = 0;
- return Int_Key;
- }
- case "Rijndael":
- {
- Int_Key[0] = 128;
- Int_Key[1] = 192;
- Int_Key[2] = 256;
- Int_Key[3] = -1;
- return Int_Key;
- }
- case "TripleDES":
- {
- Int_Key[0] = 128;
- Int_Key[1] = 192;
- Int_Key[2] = 64;
- Int_Key[3] = 0;
- return Int_Key;
- }
- }
- return Int_Key;
- }
-
-
-
-
-
-
- public CryptoHelper(string algrorithmName, string Key, string IV)
- {
- provider = SymmetricAlgorithm.Create(algrorithmName);
- provider.Key = Encoding.UTF8.GetBytes(Key);
- provider.IV = Encoding.UTF8.GetBytes(IV);
- encryptor = provider.CreateEncryptor();
- decryptor = provider.CreateDecryptor();
- }
- ~CryptoHelper()
- {
- provider.Clear();
- }
-
-
-
-
-
- public void EncryptFile(String inName, String outName)
- {
-
- FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
- FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
- fout.SetLength(0);
-
- byte[] bin = new byte[per_length];
- long rdlen = 0;
- long totlen = fin.Length;
- int len;
-
- CryptoStream encStream = new CryptoStream(fout,encryptor, CryptoStreamMode.Write);
-
- while (rdlen < totlen)
- {
- len = fin.Read(bin, 0, per_length);
- encStream.Write(bin, 0, len);
- rdlen = rdlen + len;
- }
- encStream.Flush();
- encStream.Close();
- fout.Close();
- fin.Close();
- }
-
-
-
-
-
- public void DecryptFile(String inName, String outName)
- {
-
- FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
- FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
- fout.SetLength(0);
-
- byte[] bin = new byte[per_length];
- long rdlen = 0;
- long totlen = fin.Length;
- int len;
- CryptoStream decStream = new CryptoStream(fout,decryptor, CryptoStreamMode.Write);
-
- while (rdlen < totlen)
- {
- len = fin.Read(bin, 0, per_length);
- decStream.Write(bin, 0, len);
- rdlen = rdlen + len;
- }
- decStream.Flush();
- decStream.Close();
- fout.Close();
- fin.Close();
- }
- }
- }
下面是界面的设计

下面是界面的一些设置的代码,这些代码由系统自己生成
- namespace PassWord
- {
- partial class MainForm
- {
-
-
-
- private System.ComponentModel.IContainer components = null;
-
-
-
-
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows 窗体设计器生成的代码
-
-
-
-
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
- this.pass_cb_style = new System.Windows.Forms.ComboBox();
- this.label1 = new System.Windows.Forms.Label();
- this.pass_tb_first = new System.Windows.Forms.TextBox();
- this.pass_tb_second = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.pass_but_encrty = new System.Windows.Forms.Button();
- this.pass_but_decrty = new System.Windows.Forms.Button();
- this.del_file_checkBox = new System.Windows.Forms.CheckBox();
- this.label4 = new System.Windows.Forms.Label();
- this.timer1 = new System.Windows.Forms.Timer(this.components);
- this.label5 = new System.Windows.Forms.Label();
- this.SuspendLayout();
-
-
-
- this.pass_cb_style.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
- this.pass_cb_style.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.pass_cb_style.Font = new System.Drawing.Font("Times New Roman", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.pass_cb_style.FormattingEnabled = true;
- this.pass_cb_style.Items.AddRange(new object[] {
- "DES",
- "RC2",
- "Rijndael",
- "TripleDES"});
- this.pass_cb_style.Location = new System.Drawing.Point(174, 16);
- this.pass_cb_style.Name = "pass_cb_style";
- this.pass_cb_style.Size = new System.Drawing.Size(167, 30);
- this.pass_cb_style.TabIndex = 0;
- this.pass_cb_style.SelectedIndexChanged += new System.EventHandler(this.pass_cb_style_SelectedIndexChanged);
-
-
-
- this.label1.AutoSize = true;
- this.label1.BackColor = System.Drawing.Color.Transparent;
- this.label1.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label1.Location = new System.Drawing.Point(18, 20);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(149, 20);
- this.label1.TabIndex = 1;
- this.label1.Text = "选择加密的算法";
-
-
-
- this.pass_tb_first.Font = new System.Drawing.Font("Times New Roman", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.pass_tb_first.Location = new System.Drawing.Point(174, 71);
- this.pass_tb_first.Name = "pass_tb_first";
- this.pass_tb_first.PasswordChar = '*';
- this.pass_tb_first.Size = new System.Drawing.Size(167, 30);
- this.pass_tb_first.TabIndex = 2;
- this.pass_tb_first.Leave += new System.EventHandler(this.pass_tb_first_Leave);
- this.pass_tb_first.KeyUp += new System.Windows.Forms.KeyEventHandler(this.pass_tb_first_KeyUp);
- this.pass_tb_first.Enter += new System.EventHandler(this.pass_tb_first_Enter);
-
-
-
- this.pass_tb_second.Font = new System.Drawing.Font("Times New Roman", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.pass_tb_second.Location = new System.Drawing.Point(176, 164);
- this.pass_tb_second.Name = "pass_tb_second";
- this.pass_tb_second.PasswordChar = '*';
- this.pass_tb_second.Size = new System.Drawing.Size(165, 30);
- this.pass_tb_second.TabIndex = 3;
- this.pass_tb_second.Leave += new System.EventHandler(this.pass_tb_second_Leave);
- this.pass_tb_second.KeyUp += new System.Windows.Forms.KeyEventHandler(this.pass_tb_second_KeyUp);
-
-
-
- this.label2.AutoSize = true;
- this.label2.BackColor = System.Drawing.Color.Transparent;
- this.label2.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label2.Location = new System.Drawing.Point(18, 76);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(129, 20);
- this.label2.TabIndex = 4;
- this.label2.Text = "初次输入密码";
-
-
-
- this.label3.AutoSize = true;
- this.label3.BackColor = System.Drawing.Color.Transparent;
- this.label3.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label3.Location = new System.Drawing.Point(18, 169);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(129, 20);
- this.label3.TabIndex = 5;
- this.label3.Text = "再次输入密码";
-
-
-
- this.pass_but_encrty.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.pass_but_encrty.ForeColor = System.Drawing.Color.Red;
- this.pass_but_encrty.Location = new System.Drawing.Point(40, 212);
- this.pass_but_encrty.Name = "pass_but_encrty";
- this.pass_but_encrty.Size = new System.Drawing.Size(77, 34);
- this.pass_but_encrty.TabIndex = 6;
- this.pass_but_encrty.Text = "加密";
- this.pass_but_encrty.UseVisualStyleBackColor = true;
- this.pass_but_encrty.Click += new System.EventHandler(this.pass_but_encrty_Click);
-
-
-
- this.pass_but_decrty.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.pass_but_decrty.ForeColor = System.Drawing.Color.Lime;
- this.pass_but_decrty.Location = new System.Drawing.Point(201, 212);
- this.pass_but_decrty.Name = "pass_but_decrty";
- this.pass_but_decrty.Size = new System.Drawing.Size(77, 34);
- this.pass_but_decrty.TabIndex = 7;
- this.pass_but_decrty.Text = "解密";
- this.pass_but_decrty.UseVisualStyleBackColor = true;
- this.pass_but_decrty.Click += new System.EventHandler(this.pass_but_decrty_Click);
-
-
-
- this.del_file_checkBox.AutoSize = true;
- this.del_file_checkBox.BackColor = System.Drawing.Color.Transparent;
- this.del_file_checkBox.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.del_file_checkBox.Location = new System.Drawing.Point(40, 269);
- this.del_file_checkBox.Name = "del_file_checkBox";
- this.del_file_checkBox.Size = new System.Drawing.Size(128, 24);
- this.del_file_checkBox.TabIndex = 8;
- this.del_file_checkBox.Text = "删除源文件";
- this.del_file_checkBox.UseVisualStyleBackColor = false;
-
-
-
- this.label4.AutoSize = true;
- this.label4.BackColor = System.Drawing.Color.Transparent;
- this.label4.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label4.Location = new System.Drawing.Point(18, 119);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(119, 20);
- this.label4.TabIndex = 10;
- this.label4.Text = "密 码 强 度";
-
-
-
- this.timer1.Interval = 500;
- this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
-
-
-
- this.label5.AutoSize = true;
- this.label5.BackColor = System.Drawing.Color.White;
- this.label5.Font = new System.Drawing.Font("楷体_GB2312", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.label5.ForeColor = System.Drawing.Color.Red;
- this.label5.Location = new System.Drawing.Point(172, 119);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(69, 20);
- this.label5.TabIndex = 11;
- this.label5.Text = "非常弱";
-
-
-
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
- this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
- this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.ClientSize = new System.Drawing.Size(366, 314);
- this.Controls.Add(this.label5);
- this.Controls.Add(this.label4);
- this.Controls.Add(this.del_file_checkBox);
- this.Controls.Add(this.pass_but_decrty);
- this.Controls.Add(this.pass_but_encrty);
- this.Controls.Add(this.label3);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.pass_tb_second);
- this.Controls.Add(this.pass_tb_first);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.pass_cb_style);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "MainForm";
- this.Text = "加密与解密";
- this.Load += new System.EventHandler(this.Form1_Load);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.ComboBox pass_cb_style;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox pass_tb_first;
- private System.Windows.Forms.TextBox pass_tb_second;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Button pass_but_encrty;
- private System.Windows.Forms.Button pass_but_decrty;
- private System.Windows.Forms.CheckBox del_file_checkBox;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Timer timer1;
- private System.Windows.Forms.Label label5;
- }
- }
其中控件的一些名称如表所示:
控件类别 |
控件名称 |
控件的用途 |
下拉式列表框 |
pass_cb_style |
用来选择加密的算法 |
文本框 |
pass_tb_first |
让用户输入密码 |
文本框 |
pass_tb_second |
让用户输入密码,验证密码 |
按钮 |
pass_but_encrty |
加密按钮 |
按钮 |
pass_but_decrty |
解密按钮 |
标签 |
label5 |
指示密码强度 |
复选框 |
del_file_checkBox |
是否删除源文件复选框 |
其中还放置了一个Timer控件,主要用来测试密码强度。
下面就是界面部分编制的代码了
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace PassWord
- {
- public partial class MainForm : Form
- {
- private string InputFile = string.Empty;
- private string OutputFile = string.Empty;
- private string algrorithmName = "DES";
- private int lowerChar = 0;
- private int upperChar = 0;
- private int numChar = 0;
- private int otherChar = 0;
- private int userPassLen = 0;
- private int userPassScore = 0;
- public MainForm()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
-
- pass_cb_style.Text = "DES";
- pass_but_encrty.Enabled = false;
- pass_but_decrty.Enabled = false;
- timer1.Enabled = false;
- }
- private void pass_but_encrty_Click(object sender, EventArgs e)
- {
- string Key = GetKey();
- string IV = GetIV();
- CryptoHelper encFile = new CryptoHelper(algrorithmName, Key, IV);
- GetIOFileName();
- if (InputFile != null && OutputFile != null)
- {
- try
- {
- encFile.EncryptFile(InputFile, OutputFile);
- MessageBox.Show("加密成功!!!", "恭喜!成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (del_file_checkBox.Checked == true)
- DeleteFile(InputFile);
- }
- catch
- {
- MessageBox.Show("加密失败", "十分遗憾", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- private void pass_but_decrty_Click(object sender, EventArgs e)
- {
- string Key = GetKey();
- string IV = GetIV();
- CryptoHelper decFile = new CryptoHelper(algrorithmName, Key, IV);
- GetIOFileName();
- if (InputFile != null && OutputFile != null)
- {
- try
- {
- decFile.DecryptFile(InputFile, OutputFile);
- MessageBox.Show("解密成功!!!", "恭喜!成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (del_file_checkBox.Checked == true)
- DeleteFile(InputFile);
- }
- catch
- {
- MessageBox.Show("解密失败", "十分遗憾", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
-
-
-
-
- public void DeleteFile(string filename)
- {
- try
- {
- File.Delete(filename);
- }
- catch (Exception e)
- {
- MessageBox.Show(e.ToString());
- }
- }
-
-
-
- public void GetIOFileName()
- {
- OpenFileDialog openFile = new OpenFileDialog();
- openFile.Filter = "All files (*.*)|*.*";
- openFile.Title = "请你选择源文件";
- if (openFile.ShowDialog() == DialogResult.OK)
- {
- InputFile = openFile.FileName;
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.Filter = "All files (*.*)|*.*";
- saveFile.Title = "请你选择目标文件";
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- OutputFile = saveFile.FileName;
- if (OutputFile == InputFile)
- {
- OutputFile = null;
- MessageBox.Show("源文件不能与目标文件为同一个文件", "错误", MessageBoxButtons.OK);
- }
- }
- else
- OutputFile = null;
- }
- else
- InputFile = null;
- }
-
-
-
-
-
- private void pass_cb_style_SelectedIndexChanged(object sender, EventArgs e)
- {
- algrorithmName = pass_cb_style.Text;
- }
-
-
-
-
-
- private void pass_tb_first_KeyUp(object sender, KeyEventArgs e)
- {
- }
- private void pass_tb_second_Leave(object sender, EventArgs e)
- {
- if (pass_tb_first.Text != pass_tb_second.Text)
- {
- MessageBox.Show("两次输入的密码不一致", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- pass_tb_second.Text = "";
- }
- }
- private void pass_tb_second_KeyUp(object sender, KeyEventArgs e)
- {
- if (pass_tb_first.Text == pass_tb_second.Text)
- {
- pass_but_decrty.Enabled = true;
- pass_but_encrty.Enabled = true;
- }
- else
- {
- pass_but_decrty.Enabled = false;
- pass_but_encrty.Enabled = false;
- }
- }
-
-
-
-
- private string GetKey()
- {
- string passWord = pass_tb_first.Text;
- int[] LegalLength = new int[4];
- LegalLength = CryptoHelper.GetKeyLength(algrorithmName);
- int plength = passWord.Length;
- switch (algrorithmName)
- {
- case "DES":
- {
- if (plength == LegalLength[0] / 8)
- passWord = pass_tb_first.Text;
- if (plength > LegalLength[0] / 8)
- passWord = pass_tb_first.Text.Substring(0, 8);
- if (plength < LegalLength[0] / 8)
- passWord = RepeatStr(pass_tb_first.Text, 8);
- break;
- }
- case "RC2":
- {
- if (plength >= LegalLength[0] / 8 && plength <= LegalLength[1] / 8)
- passWord = pass_tb_first.Text;
- if (plength > LegalLength[1] / 8)
- passWord = pass_tb_first.Text.Substring(0, 16);
- if (plength < LegalLength[0] / 8)
- passWord = RepeatStr(pass_tb_first.Text, 5);
- break;
- }
- case "TripleDES":
- {
- if (plength >= LegalLength[0] / 8 && plength <= LegalLength[1] / 8)
- {
- passWord = pass_tb_first.Text;
- if (plength % 2 != 0)
- {
- passWord += passWord.Substring(0, 1);
- plength = passWord.Length;
- }
- }
- if (plength > LegalLength[1] / 8)
- passWord = pass_tb_first.Text.Substring(0, 24);
- if (plength < LegalLength[0] / 8)
- passWord = RepeatStr(pass_tb_first.Text, 16);
- break;
- }
- case "Rijndael":
- {
- passWord = pass_tb_first.Text;
- if (plength < LegalLength[0] / 8)
- passWord = RepeatStr(passWord, 16);
- if (plength < LegalLength[1] / 8)
- passWord = RepeatStr(passWord, 24);
- if (plength < LegalLength[2] / 8)
- passWord = RepeatStr(passWord, 32);
- break;
- }
- }
- return passWord;
- }
-
-
-
-
- private string GetIV()
- {
- string iv = pass_tb_first.Text;
- int len = iv.Length;
- switch (algrorithmName)
- {
- case "Rijndael":
- {
- if (len < 16)
- iv = RepeatStr(pass_tb_first.Text, 16);
- else
- iv = pass_tb_first.Text.Substring(0, 16);
- break;
- }
- default:
- {
- if (len < 8)
- iv = RepeatStr(pass_tb_first.Text, 8);
- else
- iv = pass_tb_first.Text.Substring(0, 8);
- break;
- }
- }
- return iv;
- }
-
-
-
-
-
-
- private string RepeatStr(string str, int length)
- {
- int lenold = str.Length;
- string temp = str;
- int len = lenold;
- if (len >= length)
- return str;
- while (len < length)
- {
- if (length - len < lenold)
- {
- str += str.Substring(0, length - len);
- len += length - len;
- }
- else
- {
- str += temp;
- len += lenold;
- }
- }
- return str;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- userPassScore = 0;
- userPassLen = 0;
- userPassLen=pass_tb_first.Text.Length;
- lowerChar = 0;
- upperChar = 0;
- numChar = 0;
- otherChar = 0;
- foreach (char c in pass_tb_first.Text.ToCharArray())
- {
- if (Char.IsLower(c))
- {
- lowerChar++;
- }
- if (Char.IsUpper(c))
- {
- upperChar++;
- }
- if (Char.IsDigit(c))
- {
- numChar++;
- }
- if (Char.IsSymbol(c) || Char.IsPunctuation(c) || Char.IsSeparator(c) || Char.IsWhiteSpace(c))
- {
- otherChar++;
- }
- }
-
- if (userPassLen <= 4 && userPassLen!=0)
- userPassScore = 5;
- if (userPassLen >= 5 && userPassLen <= 7)
- userPassScore = 10;
- if (userPassLen >= 8)
- userPassScore = 25;
- if ((lowerChar != 0 || upperChar != 0) && (userPassLen == lowerChar || userPassLen == upperChar))
- {
- userPassScore += 10;
- }
- if ((lowerChar != 0 ||upperChar != 0 )&& (userPassLen != lowerChar || userPassLen != upperChar))
- {
- userPassScore += 20;
- }
- if (numChar != 0)
- {
- userPassScore += 10;
- if (numChar > 3)
- userPassScore += 20;
- }
- if (otherChar != 0)
- {
- userPassScore += 10;
- if (otherChar > 3)
- userPassScore += 25;
- }
- if (lowerChar != 0 && upperChar != 0 && numChar != 0 && otherChar != 0)
- {
- userPassScore += 5;
- }
- if(userPassScore<25)
- label5.Text = "非常弱";
- if (userPassScore >= 25 && userPassScore < 50)
- {
- label5.Text = "弱";
- label5.ForeColor = System.Drawing.Color.Red;
- }
- if (userPassScore >= 50 && userPassScore < 60)
- {
- label5.Text = "一般";
- label5.ForeColor = System.Drawing.Color.Blue;
- }
- if (userPassScore >= 60 && userPassScore < 70)
- {
- label5.Text = "强";
- label5.ForeColor = System.Drawing.Color.YellowGreen;
- }
- if (userPassScore >= 70 && userPassScore < 80)
- {
- label5.Text = "非常强";
- label5.ForeColor = System.Drawing.Color.LightGreen;
- }
- if (userPassScore >= 80 && userPassScore < 90)
- {
- label5.Text = "安全";
- label5.ForeColor = System.Drawing.Color.GreenYellow;
- }
- if (userPassScore >= 90)
- {
- label5.Text = "非常安全";
- label5.ForeColor = System.Drawing.Color.Green;
- }
- }
- private void pass_tb_first_Enter(object sender, EventArgs e)
- {
- timer1.Enabled = true;
- }
- private void pass_tb_first_Leave(object sender, EventArgs e)
- {
- timer1.Enabled = false;
- }
- }
- }
最后的一点补充说明
加密算法名称 |
密钥位数(KEY) |
初始化向量(IV) |
DES |
64位 |
64位 |
RC2 |
40位到128位,位数递增8 |
64位 |
Rijndael |
128,192,256 |
128--256 每次递增64位 |
TripleDES |
128位到192位 |
64位 |