1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.Buffers.Text;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- namespace IoTIntegrationPlatform.Common
- {
- /// <summary>
- /// 加解密公共类
- /// </summary>
- public static class EncryptHelper
- {
- //private readonly static string key = "DD57F2D5CAA11BDC";
- /// <summary>
- /// AES64位加密
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- public static string AESEncrypt(string content,string key)
- {
- string result = string.Empty;
- try
- {
- byte[] bytes = AESHelper.Encrypt(content, key);
- result = Convert.ToBase64String(bytes);
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// AES64位解密
- /// </summary>
- /// <param name="content"></param>
- public static string AESDecryption(string content, string key)
- {
- string result = string.Empty;
- try
- {
- byte[] bytes = Convert.FromBase64String(content);
- result = Encoding.Default.GetString(AESHelper.Decrypt(bytes, key));
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- }
- }
|