1
using System;
2
using System.IO;
3
using System.Security.Cryptography;
4![]()
5
namespace Vavic
6
{
7
/// <summary>
8
/// Security 的摘要说明。
9
/// </summary>
10
public class Security
11
{
12
const string KEY_6 = "VavicApp";
13
const string IV_6 = "VavicApp"; //注意了,是8个字符,6位
14![]()
15
public Security()
16
{
17
//
18
// TODO: 在此处添加构造函数逻辑
19
//
20
}
21![]()
22
public static string Encode(string data)
23
{
24
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_6);
25
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_6);
26![]()
27
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
28
int i = cryptoProvider.KeySize;
29
MemoryStream ms = new MemoryStream();
30
CryptoStream cst = new CryptoStream(ms,cryptoProvider.CreateEncryptor(byKey,byIV),CryptoStreamMode.Write);
31![]()
32
StreamWriter sw = new StreamWriter(cst);
33
sw.Write(data);
34
sw.Flush();
35
cst.FlushFinalBlock();
36
sw.Flush();
37
return Convert.ToBase6String(ms.GetBuffer(),0,(int)ms.Length);
38![]()
39
}
40![]()
41
public static string Decode(string data)
42
{
43
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_6);
44
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_6);
45![]()
46
byte[] byEnc;
47
try
48
{
49
byEnc = Convert.FromBase6String(data);
50
}
51
catch
52
{
53
return null;
54
}
55![]()
56
DESCryptoServiceProvider cryptoProvider =
using System;2
using System.IO;3
using System.Security.Cryptography;4

5
namespace Vavic6
{7
/// <summary>8
/// Security 的摘要说明。9
/// </summary>10
public class Security11
{12
const string KEY_6 = "VavicApp";13
const string IV_6 = "VavicApp"; //注意了,是8个字符,6位14

15
public Security()16
{17
//18
// TODO: 在此处添加构造函数逻辑19
//20
}21

22
public static string Encode(string data)23
{24
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_6);25
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_6);26

27
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();28
int i = cryptoProvider.KeySize;29
MemoryStream ms = new MemoryStream();30
CryptoStream cst = new CryptoStream(ms,cryptoProvider.CreateEncryptor(byKey,byIV),CryptoStreamMode.Write);31

32
StreamWriter sw = new StreamWriter(cst);33
sw.Write(data);34
sw.Flush();35
cst.FlushFinalBlock();36
sw.Flush();37
return Convert.ToBase6String(ms.GetBuffer(),0,(int)ms.Length);38

39
}40

41
public static string Decode(string data)42
{ 43
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_6);44
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_6);45

46
byte[] byEnc;47
try48
{49
byEnc = Convert.FromBase6String(data);50
}51
catch52
{53
return null;54
}55

56
DESCryptoServiceProvider cryptoProvider =



浙公网安备 33010602011771号