@@ -49,112 +49,6 @@ public byte[] Encrypt(ReadOnlySpan<byte> data, ReadOnlySpan<byte> key)
4949 throw new NotSupportedException ( "You should no longer use AES-CBC as your encryption method" ) ;
5050 }
5151
52- /// <summary>
53- /// 使用特定的 AES 算法加密数据
54- /// </summary>
55- /// <param name = "input" > 需要加密的数据 </ param >
56- /// < param name="key">密钥</param>
57- /// <returns>Base64 编码的加密数据</returns>
58- /// <exception cref = "ArgumentNullException" > 如果 key 为 null 或者空</exception>
59- //private static string AesEncrypt(string input, string key)
60- //{
61- // if (string.IsNullOrEmpty(input))
62- // return string.Empty;
63- // if (string.IsNullOrEmpty(key))
64- // throw new ArgumentNullException(nameof(key));
65-
66- // using var aes = Aes.Create();
67- // aes.KeySize = 256;
68- // aes.BlockSize = 128;
69- // aes.Mode = CipherMode.CBC;
70- // aes.Padding = PaddingMode.PKCS7;
71- // var salt = new byte[32];
72- //#if NET6_0_OR_GREATER
73- // using (var rng = RandomNumberGenerator.Create())
74- //#else
75- // using (var rng = new RNGCryptoServiceProvider())
76- //#endif
77- // {
78- // rng.GetBytes(salt);
79- // }
80-
81- //#pragma warning disable SYSLIB0041
82- // using (var deriveBytes = new Rfc2898DeriveBytes(key, salt, 1000))
83- // {
84- // aes.Key = deriveBytes.GetBytes(aes.KeySize / 8);
85- // aes.GenerateIV();
86- // }
87- //#pragma warning restore SYSLIB0041
88-
89- // using (var ms = new MemoryStream())
90- // {
91- // ms.Write(salt, 0, salt.Length);
92- // ms.Write(aes.IV, 0, aes.IV.Length);
93-
94- // using (var cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write))
95- // {
96- // var data = Encoding.UTF8.GetBytes(input);
97- // cs.Write(data, 0, data.Length);
98- // }
99-
100- // return Convert.ToBase64String(ms.ToArray());
101- // }
102- // }
103-
104- /// <summary>
105- /// 使用特定的 AES 算法解密数据
106- /// </summary>
107- /// <param name="input">Base64 编码的加密数据</param>
108- /// <param name="key">密钥</param>
109- /// <returns>返回解密文本</returns>
110- /// <exception cref="ArgumentNullException">如果 Key 为 null 或空</exception>
111- /// <exception cref="ArgumentException">如果 input 数据错误</exception>
112- // private static string AesDecrypt(string input, string key)
113- // {
114- // if (string.IsNullOrEmpty(input))
115- // return string.Empty;
116- // if (string.IsNullOrEmpty(key))
117- // throw new ArgumentNullException(nameof(key));
118-
119-
120- // using var aes = Aes.Create();
121- // aes.KeySize = 256;
122- // aes.BlockSize = 128;
123- // aes.Mode = CipherMode.CBC;
124- // aes.Padding = PaddingMode.PKCS7;
125-
126- // var encryptedData = Convert.FromBase64String(input);
127-
128- // var salt = new byte[32];
129- // Array.Copy(encryptedData, 0, salt, 0, salt.Length);
130-
131- // var iv = new byte[aes.BlockSize / 8];
132- // Array.Copy(encryptedData, salt.Length, iv, 0, iv.Length);
133- // aes.IV = iv;
134-
135- // if (encryptedData.Length < salt.Length + iv.Length)
136- // {
137- // throw new ArgumentException("加密数据格式无效或已损坏");
138- // }
139-
140- //#pragma warning disable SYSLIB0041
141- // using (var deriveBytes = new Rfc2898DeriveBytes(key, salt, 1000))
142- // {
143- // aes.Key = deriveBytes.GetBytes(aes.KeySize / 8);
144- // }
145- //#pragma warning restore SYSLIB0041
146-
147- // var cipherTextLength = encryptedData.Length - salt.Length - iv.Length;
148- // using (var ms = new MemoryStream(encryptedData, salt.Length + iv.Length, cipherTextLength))
149- // {
150- // using (var cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Read))
151- // {
152- // using (var sr = new StreamReader(cs, Encoding.UTF8))
153- // {
154- // return sr.ReadToEnd();
155- // }
156- // }
157- // }
158- // }
52+ public bool IsSupported { get => false ; }
15953 }
16054}
0 commit comments