wzp
2022-03-01 eb62f992f048d3721485d6d3c1e02a4a9a0b0ce6
1
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
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web.Security;
 
namespace Common
{
  public class DESEncrypt
  {
    public static string Encrypt(string Text)
    {
      return DESEncrypt.Encrypt(Text, "litianping");
    }
 
    public static string Encrypt(string Text, string sKey)
    {
      DESCryptoServiceProvider cryptoServiceProvider = new DESCryptoServiceProvider();
      byte[] bytes = Encoding.Default.GetBytes(Text);
      cryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
      cryptoServiceProvider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
      MemoryStream memoryStream = new MemoryStream();
      CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, cryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write);
      cryptoStream.Write(bytes, 0, bytes.Length);
      cryptoStream.FlushFinalBlock();
      StringBuilder stringBuilder = new StringBuilder();
      foreach (byte num in memoryStream.ToArray())
        stringBuilder.AppendFormat("{0:X2}", (object) num);
      return stringBuilder.ToString();
    }
 
    public static string Decrypt(string Text)
    {
      return DESEncrypt.Decrypt(Text, "litianping");
    }
 
    public static string Decrypt(string Text, string sKey)
    {
      DESCryptoServiceProvider cryptoServiceProvider = new DESCryptoServiceProvider();
      int length = Text.Length / 2;
      byte[] buffer = new byte[length];
      for (int index = 0; index < length; ++index)
      {
        int num = Convert.ToInt32(Text.Substring(index * 2, 2), 16);
        buffer[index] = (byte) num;
      }
      cryptoServiceProvider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
      cryptoServiceProvider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
      MemoryStream memoryStream = new MemoryStream();
      CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, cryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
      cryptoStream.Write(buffer, 0, buffer.Length);
      cryptoStream.FlushFinalBlock();
      return Encoding.Default.GetString(memoryStream.ToArray());
    }
  }
}