using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using WMS.Util;
namespace WMS.BZServices
{
public class SysSecurityHelp
{
const string AES256IV = "C686096CDBB34A77";
const string AES256Key = "C628CE01C4F84037BEA124C90B3EE1FC";
public static string Aes256Encrypt(string EncryptText)
{
try
{
return SecurityUtil.AesEncrypt(EncryptText, AES256Key, AES256IV);
}
catch (Exception ex)
{
throw ex;
}
}
public static string Aes256Decrypt(string DecryptText)
{
try
{
return SecurityUtil.AesDecrypt(DecryptText, AES256Key, AES256IV);
}
catch (Exception ex)
{
throw ex;
}
}
public static string Aes256Encrypt(string EncryptText, string AES256Key)
{
try
{
return SecurityUtil.AesEncrypt(EncryptText, AES256Key, AES256IV);
}
catch (Exception ex)
{
throw ex;
}
}
public static string Aes256Decrypt(string DecryptText, string AES256Key)
{
try
{
return SecurityUtil.AesDecrypt(DecryptText, AES256Key, AES256IV);
}
catch (Exception ex)
{
throw ex;
}
}
#region "MD5加密"
///
/// MD5加密
///
/// 加密字符
/// 加密位数16/32
///
public static string Encrypt(string str, int code)
{
string strEncrypt = string.Empty;
if (code == 16)
{
strEncrypt = Hash(str).Substring(8, 16);
}
if (code == 32)
{
strEncrypt = Hash(str);
}
return strEncrypt;
}
///
/// 32位MD5加密(小写)
///
/// 输入字段
///
public static string Hash(string input)
{
var md5Hasher = MD5.Create();
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
#endregion
}
}