加密
1:我们经常的加密【md5】
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("welcom", System.Web.Configuration.FormsAuthPasswordFormat.MD5);
2:李天平老师的一个加密class
1
namespace LTP.Common.DEncrypt
2
{
3
using System;
4
using System.Security.Cryptography;
5
using System.Text;
6
7
public class DEncrypt
8
{
9
public static byte[] Decrypt(byte[] encrypted)
10
{
11
byte[] bytes = Encoding.Default.GetBytes("LITIANPING");
12
return Decrypt(encrypted, bytes);
13
}
14
15
public static string Decrypt(string original)
16
{
17
return Decrypt(original, "LITIANPING", Encoding.Default);
18
}
19
20
public static byte[] Decrypt(byte[] encrypted, byte[] key)
21
{
22
TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
23
provider.Key = MakeMD5(key);
24
provider.Mode = CipherMode.ECB;
25
return provider.CreateDecryptor().TransformFinalBlock(encrypted, 0, encrypted.Length);
26
}
27
28
public static string Decrypt(string original, string key)
29
{
30
return Decrypt(original, key, Encoding.Default);
31
}
32
33
public static string Decrypt(string encrypted, string key, Encoding encoding)
34
{
35
byte[] buffer = Convert.FromBase64String(encrypted);
36
byte[] bytes = Encoding.Default.GetBytes(key);
37
return encoding.GetString(Decrypt(buffer, bytes));
38
}
39
40
public static string Encrypt(string original)
41
{
42
return Encrypt(original, "LITIANPING");
43
}
44
45
public static byte[] Encrypt(byte[] original)
46
{
47
byte[] bytes = Encoding.Default.GetBytes("LITIANPING");
48
return Encrypt(original, bytes);
49
}
50
51
public static string Encrypt(string original, string key)
52
{
53
byte[] bytes = Encoding.Default.GetBytes(original);
54
byte[] buffer2 = Encoding.Default.GetBytes(key);
55
return Convert.ToBase64String(Encrypt(bytes, buffer2));
56
}
57
58
public static byte[] Encrypt(byte[] original, byte[] key)
59
{
60
TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
61
provider.Key = MakeMD5(key);
62
provider.Mode = CipherMode.ECB;
63
return provider.CreateEncryptor().TransformFinalBlock(original, 0, original.Length);
64
}
65
66
public static byte[] MakeMD5(byte[] original)
67
{
68
byte[] buffer = new MD5CryptoServiceProvider().ComputeHash(original);
69
return buffer;
70
}
71
}
72
}
73
74

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

1
namespace LTP.Common.DEncrypt
2
{
3
using System;
4
using System.IO;
5
using System.Security.Cryptography;
6
using System.Text;
7
using System.Web.Security;
8
9
public class DESEncrypt
10
{
11
public static string Decrypt(string Text)
12
{
13
return Decrypt(Text, "litianping");
14
}
15
16
public static string Decrypt(string Text, string sKey)
17
{
18
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
19
int num = Text.Length / 2;
20
byte[] buffer = new byte[num];
21
for (int i = 0; i < num; i++)
22
{
23
int num3 = Convert.ToInt32(Text.Substring(i * 2, 2), 0x10);
24
buffer[i] = (byte) num3;
25
}
26
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
27
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
28
MemoryStream stream = new MemoryStream();
29
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
30
stream2.Write(buffer, 0, buffer.Length);
31
stream2.FlushFinalBlock();
32
return Encoding.Default.GetString(stream.ToArray());
33
}
34
35
public static string Encrypt(string Text)
36
{
37
return Encrypt(Text, "litianping");
38
}
39
40
public static string Encrypt(string Text, string sKey)
41
{
42
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
43
byte[] bytes = Encoding.Default.GetBytes(Text);
44
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
45
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
46
MemoryStream stream = new MemoryStream();
47
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
48
stream2.Write(bytes, 0, bytes.Length);
49
stream2.FlushFinalBlock();
50
StringBuilder builder = new StringBuilder();
51
foreach (byte num in stream.ToArray())
52
{
53
builder.AppendFormat("{0:X2}", num);
54
}
55
return builder.ToString();
56
}
57
}
58
}
59
60

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60
