文本加密程序“PrivateData”

顾名思义,这是一个加密软件,但只限于文本加密,这个软件的灵感来自于一个雷雨交加的下午

我正在写一个下载器,休息一下,起身来到窗前,看着大雨,忽然想到了可以写一个加密文本的小程序,于是开始了写代码,然而第一次

写出来的程序让我很难受,其一很难看,其二特别死板,那么怎样才能让程序“动”起来呢第?二个版本我加人了窗口控件的滑动效果

控件滚动方法:

 1  
//具体方法
//Movegroup(string u, Panel p1, Panel p2)
//Movegroup(方向<或>,被移走的控件,被移入的控件)
//注意还要添加两个timer :Return,Next , Interval = 10
public void Movegroup(string u, Panel p1, Panel p2)
2 {
3 if (u == ">") //这是向右,
4 {
5 up1 = p1;
6 up2 = p2;
7 p2.Visible = true;
8 p1.Enabled = false;
9 p2.Enabled = false;
10 Next.Enabled = true;
11 }
12 if (u == "<")
13 {
14 up1 = p1;
15 up2 = p2;
16 p2.Visible = true;
17 p1.Enabled = false;
18 p2.Enabled = false;
19 Return.Enabled = true;
20 }
21 }
22 Panel up1, up2;
23 int a = 0;
24 int b = -580;
25 int i = 0;
26 int j = 580;
27 private void Next_Tick(object sender, EventArgs e)
28 {
29 i -= 30;
30 j -= 30;
31 up1.Location = new Point(i, up1.Location.Y);
32 up2.Location = new Point(j, up2.Location.Y);
33 if (i <= -580 || j <= 0)
34 {
35 Next.Enabled = false;
36 up2.Enabled = true;
37 up1.Enabled = false;
38 up1.Visible = false;
39 i = 0;
40 j = 580;
41 }
42 }
43 private void Return_Tick(object sender, EventArgs e)
44 {
45 a += 30;
46 b += 30;
47 up1.Location = new Point(a, up1.Location.Y);
48 up2.Location = new Point(b, up2.Location.Y);
49 if (a >= 580 || b >= 0)
50 {
51 Return.Enabled = false;
52 up2.Enabled = true;
53 up1.Visible = false;
54 up1.Enabled = false;
55 a = 0;
56 b = -580;
57 }
58 }

加密原理:

密码+问题+答案的md5 +“/”+加密后的串 组成一个文本文件,(二进制更好了)

解密原理:

先分离出文件里的 密码+问题+答案的md5在与用户输入的密码+问题+答案的md5对比

如果相符则 以此密码解密文件

如果不相符则 提示密码问题及答案错误

我使用DES加密,这是一个类

namespace Pd_kernel
{
public class Encrypt
{
/// <summary>
/// 进行DES加密。
/// </summary>
/// <param name="pToEncrypt">要加密的字符串。</param>
/// <param name="sKey">密钥,且必须为8位。</param>
/// <returns>以Base64格式返回的加密字符串。</returns>
public static string DESEncrypt(string pToEncrypt, string sKey)
{
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
des.Key
= ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV
= ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStream ms
= new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray,
0, inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
string str = Convert.ToBase64String(ms.ToArray());
ms.Close();
return str;
}
}

/// <summary>
/// 进行DES解密。
/// </summary>
/// <param name="pToDecrypt">要解密的以Base64</param>
/// <param name="sKey">密钥,且必须为8位。</param>
/// <returns>已解密的字符串。</returns>
public static string DESDecrypt(string pToDecrypt, string sKey)
{
byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
des.Key
= ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV
= ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStream ms
= new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray,
0, inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
string str = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
return str;
}
}

public static string MD5encrypt(string text, string method)
{
string strMD5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text, method);
return strMD5;
}
}
}

软件很简单,没什么特别的了,视频如下:

下载地址: https://files.cnblogs.com/1119242459blog/PrectiveData%5B2.4.0.1%5D.zip

<这是小弟第一篇博文,写的不好的请提出,我会认真学习的!!>

posted @ 2011-08-06 20:55  A Dream  阅读(562)  评论(5)    收藏  举报