123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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加密"
- /// <summary>
- /// MD5加密
- /// </summary>
- /// <param name="str">加密字符</param>
- /// <param name="code">加密位数16/32</param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 32位MD5加密(小写)
- /// </summary>
- /// <param name="input">输入字段</param>
- /// <returns></returns>
- 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
- }
- }
|