username@email.com
2025-04-27 15eb82df2d6ec539e9d4245bfe08d531e8eb6379
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
 
namespace CommonToolsCore
{
    public class AesClass
    {
        const string Key = "dau&*5asda.;lk8L";
        /// <summary>
        ///  AES 加密
        /// </summary>
        /// <param name="str">明文(待加密)</param>
        /// <param name="key">key</param>
        /// <returns>密文</returns>
        public string AesEncrypt(string str, string key = Key)
        {
            if (string.IsNullOrEmpty(str)) return null;
            Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
 
            RijndaelManaged rm = new RijndaelManaged
            {
                Key = Encoding.UTF8.GetBytes(key),
                Mode = CipherMode.ECB,
                Padding = PaddingMode.PKCS7
            };
 
            ICryptoTransform cTransform = rm.CreateEncryptor();
            Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
 
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }
        /// <summary>
        ///  AES 解密
        /// </summary>
        /// <param name="str">明文(待解密)</param>
        /// <param name="key">密文</param>
        /// <returns></returns>
        public string AesDecrypt(string str, string key = Key)
        {
            if (string.IsNullOrEmpty(str)) return null;
            Byte[] toEncryptArray = Convert.FromBase64String(str);
 
            RijndaelManaged rm = new RijndaelManaged
            {
                Key = Encoding.UTF8.GetBytes(key),
                Mode = CipherMode.ECB,
                Padding = PaddingMode.PKCS7
            };
 
            ICryptoTransform cTransform = rm.CreateDecryptor();
            Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
 
            return Encoding.UTF8.GetString(resultArray);
        }
        /// <summary>
        /// 获取规则加密字符串  用于toke附带参数
        /// </summary>
        /// <param name="rules"> 规则集合 </param>
        /// <returns> 返回规则加密字符串 </returns>
        public string EncryptRules(RuleCollection rules)
        {
            string rs = JsonConvert.SerializeObject(rules);
            return AesEncrypt(rs);
 
 
        }
 
        /// <summary>
        /// 解密字规则支付穿
        /// </summary>
        /// <param name="rules">加密的字符串</param>
        /// <returns>规则字符串类</returns>
        public RuleCollection DecryptRules(string rules)
        {
 
            string str = AesDecrypt(rules);
 
            return JsonConvert.DeserializeObject<RuleCollection>(str);
            // return AesEncrypt(rs);
 
 
        }
    }
 
 
 
 
    /// <summary>
    /// 业务权限集合和其他集合
    /// </summary>
    public class RuleCollection
    {
        /// <summary>
        /// 用户名,这个名字可能会被更改
        /// </summary>
        public string User { get; set; }
 
 
        /// <summary>
        /// 授权的服务  用字符串表示,如果有  "CGGG"代表采购公告 "ZXDSFXLS" 代表竞争对手零时权限 没有该字符串,代表没有权限
        /// </summary>
        public List<string> PrivilegeService { get; set; }
 
 
        ///// <summary>
        /////  采购公告
        ///// </summary>
        //public int CGGG { get; set; }
 
        //    /// <summary>
        //    ///  竞争对手分析 零时权限
        //    /// </summary>
        //    public int ZXDSFXLS { get; set; }
        //    /// <summary>
        //    ///  竞争对手分析
        //    /// </summary>
        //    public int ZXDSFX { get; set; }
 
    }
}