应该感谢那些指出你错误的人

借我三千虎骑,复我泱泱中华!

博客园 首页 新随笔 联系 订阅 管理
 1using System;
 2using System.IO;
 3using System.Security.Cryptography;
 4
 5namespace Vavic
 6{
 7/// <summary>
 8/// Security 的摘要说明。
 9/// </summary>

10public class Security
11{
12const string KEY_6 = "VavicApp";
13const string IV_6 = "VavicApp"//注意了,是8个字符,6位
14
15public Security()
16{
17//
18// TODO: 在此处添加构造函数逻辑
19//
20}

21
22public static string Encode(string data)
23{
24byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_6);
25byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_6);
26
27DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
28int i = cryptoProvider.KeySize;
29MemoryStream ms = new MemoryStream();
30CryptoStream cst = new CryptoStream(ms,cryptoProvider.CreateEncryptor(byKey,byIV),CryptoStreamMode.Write);
31
32StreamWriter sw = new StreamWriter(cst);
33sw.Write(data);
34sw.Flush();
35cst.FlushFinalBlock();
36sw.Flush();
37return Convert.ToBase6String(ms.GetBuffer(),0,(int)ms.Length);
38
39}

40
41public static string Decode(string data)
42
43byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_6);
44byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_6);
45
46byte[] byEnc;
47try
48{
49byEnc = Convert.FromBase6String(data);
50}

51catch
52{
53return null;
54}

55
56DESCryptoServiceProvider cryptoProvider = 
posted on 2006-05-30 18:37  落拓孤鸿  阅读(1021)  评论(2编辑  收藏  举报