|
|
using Swift.web.Component.Grid; using Swift.web.Component.Grid.gridHelper; using System; using System.Collections.Generic; using System.IO; using System.Security.Cryptography; using System.Text;
namespace Swift.web.Library { public static class WebUtils { public static string LoadSlabGrid(string masterId, string masterIdDesc, string detailIdDesc, string proc) { var grid = new SwiftGrid(); grid.ColumnList = new List<GridColumn> { new GridColumn("fromAmt", "Amt From", "40", "M"), new GridColumn("toAmt", "Amt To", "40", "M"), new GridColumn("pcnt", "Perc", "30", "M"), new GridColumn("minAmt", "Min Amt", "40", "M"), new GridColumn("maxAmt", "Max Amt", "40", "M") };
grid.GridName = "grd_slab";
grid.GridType = 1;
grid.EnableCookie = false; grid.EnableFilterCookie = false; grid.DisableJsFilter = true; grid.DisableSorting = true; grid.ShowFilterForm = false; grid.ShowPagingBar = false; grid.RowIdField = detailIdDesc;
grid.AllowEdit = false; grid.AllowDelete = false; grid.GridWidth = 225;
string sql = "EXEC " + proc + " @flag = 's', @" + masterIdDesc + " = " + grid.FilterString(masterId); grid.SetComma();
return grid.CreateGrid(sql); }
public static string DecryptString( string cipherText) { var key = GetStatic.ReadWebConfig("encryptKey");
byte[] iv = new byte[16]; byte[] buffer = Convert.FromBase64String(cipherText);
using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = iv; ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
using (MemoryStream memoryStream = new MemoryStream(buffer)) { using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, decryptor, CryptoStreamMode.Read)) { using (StreamReader streamReader = new StreamReader((Stream)cryptoStream)) { return streamReader.ReadToEnd(); } } } } } public static string EncryptString(string plainText) { var key = GetStatic.ReadWebConfig("encryptKey");
byte[] iv = new byte[16]; byte[] array;
using (Aes aes = Aes.Create()) { aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = iv;
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
using (MemoryStream memoryStream = new MemoryStream()) { using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, encryptor, CryptoStreamMode.Write)) { using (StreamWriter streamWriter = new StreamWriter((Stream)cryptoStream)) { streamWriter.Write(plainText); }
array = memoryStream.ToArray(); } } } return Convert.ToBase64String(array); } } }
|