using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc;
using ZXDT.CallCenter.MVCWeb.Controllers;
namespace CallCenterApi.Interface.Controllers.Login
{
public class AES256Controller : BaseController
{
// GET: AES256
public ActionResult Index()
{
return View();
}
private static string Key
{
//get { return @")O[NB]6,YF}+efcaj{+oESb9d8>Z'e9M"; }
get { return @")O[9d]6,YF}+efcaj{+8>Z'e9M"; }
}
///
/// AES加密
///
/// 明文
/// 32位密钥
///
public string Encrypt(string encryptStr,string ltime)
{
byte[] keyArray = UTF8Encoding.UTF8.GetBytes(Key+ltime);
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(encryptStr);
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyArray;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
///
/// AES解密
///
/// 密文
/// 密钥
///
public string Decrypt(string decryptStr, string ltime)
{
byte[] keyArray = UTF8Encoding.UTF8.GetBytes(Key+ltime );
byte[] toEncryptArray = Convert.FromBase64String(decryptStr);
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyArray;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return UTF8Encoding.UTF8.GetString(resultArray);
}
}
}