public ActionResult ResetPassword(string param = null, string IV = null) { if (param != null) { ResetPasswordViewModel result = new ResetPasswordViewModel(); CryptLib cryptLib = new CryptLib(); string key = CryptLib.getHashSha256("hrkey", 31); string emailtimeout = ""; string email = ""; string timeout = ""; try { emailtimeout = cryptLib.decrypt(param, key, IV); string[] paramlist = emailtimeout.Split(','); email = paramlist[0]; timeout = paramlist[1]; DateTime expiredate = Convert.ToDateTime(timeout); if (expiredate > DateTime.Now) { result.Email = email; } else { return(View("Error")); } } catch (Exception ex) { return(View("Error")); } return(View(result)); } else { return(View("Error")); } }
public IHttpActionResult getEncrypt(dynamic data) { dynamic objenc = new ExpandoObject(); try { string json = JsonConvert.SerializeObject(data); string iv = CryptLib.GenerateRandomIV(16); string key = CryptLib.getHashSha256("GSWS TEST", 32); string encrypttext = EncryptDecryptAlgoritham.EncryptStringAES(json, key, iv); objenc.Status = 100; objenc.encrypttext = encrypttext; objenc.key = iv; objenc.Reason = ""; return(Ok(objenc)); } catch (Exception ex) { objenc.Status = 102; objenc.Reason = ex.Message.ToString(); return(Ok(objenc)); } }
public void UpdateProfile(AccountProfileModel model) { Guid userId = this.GetCurrentUserId(); var data = this._repoUser.Find(userId); if (!string.IsNullOrEmpty(model.password)) { if (string.IsNullOrEmpty(model.newPassword)) { throw new Exception("Please provide new password."); } CryptLib _crypt = new CryptLib(); string decryptedPassword = _crypt.decrypt(data.password, data.hashKey, data.vector); if (decryptedPassword != model.password) { throw new Exception("Invalid Password."); } string hashShaKey = GetSettingValue("HRIS_HASHSHA_KEY"); string key = CryptLib.getHashSha256(hashShaKey, 31); //32 bytes = 256 bits string iv = CryptLib.GenerateRandomIV(16); string encrypted = _crypt.encrypt(model.newPassword, key, iv); data.password = encrypted; data.hashKey = key; data.vector = iv; } data.email = model.email; data.updatedBy = userId; data.updatedDate = DateTime.Now; this._repoUser.Update(data); this._unitOfWork.Save(); }
public void Create(UserModel model, out Guid userId) { using (TransactionScope ts = new TransactionScope()) { Guid companyId = this.GetCurrentCompanyId(); if (this._repoUser.Query().Filter(x => x.username == model.username).Get().Any()) { throw new Exception(model.username + " is already exists."); } var currentUser = this.GetCurrentUserId(); CryptLib _crypt = new CryptLib(); string defaultPassword = GetSettingValue("DEFAULT_PASSWORD"); string key = CryptLib.getHashSha256(GetSettingValue("HRIS_HASHSHA_KEY"), 31); //32 bytes = 256 bits string iv = CryptLib.GenerateRandomIV(16); string encrypted = _crypt.encrypt(defaultPassword, key, iv); var ins = this._repoUser.Insert(new sys_User() { companyId = this.GetCurrentCompanyId(), username = model.username, password = encrypted, email = model.email, hashKey = key, vector = iv, status = (int)UserStatus.Active, updatedBy = currentUser, }); this._unitOfWork.Save(); ts.Complete(); userId = ins.id; } }
public void Update(UserModel model) { var data = this._repoUser.Find(model.id); if (model.username != data.username) { if (this._repoUser.Query().Filter(x => x.username == model.username).Get().Any()) { throw new Exception(model.username + " is already exists."); } data.username = model.username; } if (model.UserStatus.value == (int)UserStatus.ResetPassword) { CryptLib _crypt = new CryptLib(); string defaultPassword = GetSettingValue("DEFAULT_PASSWORD"); string hashShaKey = GetSettingValue("HRIS_HASHSHA_KEY"); string key = CryptLib.getHashSha256(hashShaKey, 31); //32 bytes = 256 bits string iv = CryptLib.GenerateRandomIV(16); string encrypted = _crypt.encrypt(defaultPassword, key, iv); data.password = encrypted; data.hashKey = key; data.vector = iv; } data.email = model.email; data.status = model.UserStatus.value; this._repoUser.Update(data); this._unitOfWork.Save(); }
public static string Decrypt(string data, string key, string iv) { CryptLib _crypt = new CryptLib(); //16 bytes = 128 bits key = CryptLib.getHashSha256(key, 32); //32 bytes = 256 bits return(_crypt.decrypt(data, key, iv)); }
//-> encrypt string public static string EncryptString(string pwd) { CryptLib _crypt = new CryptLib(); string plainText = pwd; string iv = "Xsoft"; // CryptLib.GenerateRandomIV(16); //16 bytes = 128 bits string key = CryptLib.getHashSha256("@XSoft201701", 31); //32 bytes = 256 bits return(_crypt.encrypt(plainText, key, iv)); }
public static string Encrypt(string data, string key) { CryptLib _crypt = new CryptLib(); String iv = CryptLib.GenerateRandomIV(16); //16 bytes = 128 bits key = CryptLib.getHashSha256(key, 31); //32 bytes = 256 bits String cypherText = _crypt.encrypt(data, key, iv); return(cypherText); }
public static void Main(String [] args) { CryptLib _crypt = new CryptLib(); string plainText = "This is the text to be encrypted"; String iv = CryptLib.GenerateRandomIV(16); //16 bytes = 128 bits string key = CryptLib.getHashSha256("my secret key", 31); //32 bytes = 256 bits String cypherText = _crypt.encrypt(plainText, key, iv); Console.WriteLine("iv=" + iv); Console.WriteLine("key=" + key); Console.WriteLine("Cypher text=" + cypherText); Console.WriteLine("Plain text =" + _crypt.decrypt(cypherText, key, iv)); }
public void ValidateLogin(string companyCode, string username, string password, out Guid sessionId) { using (TransactionScope ts = new TransactionScope()) { Guid companyId = this._repoCompany.Query().Filter(x => x.code == companyCode).Get().Select(x => x.id).FirstOrDefault(); var checkUser = this._repoUser.Query().Filter(x => x.username == username && x.companyId == companyId).Get(); if (!checkUser.Any()) { throw new Exception("Invalid Username"); } var user = checkUser.Single(); var status = (UserStatus)user.status; switch (status) { case UserStatus.Disabled: throw new Exception("User has been disabled"); case UserStatus.Locked: throw new Exception("User has been Locked"); default: break; } CryptLib _crypt = new CryptLib(); string hashShaKey = GetSettingValue(companyId, "HRIS_HASHSHA_KEY"); string key = CryptLib.getHashSha256(hashShaKey, 31); //32 bytes = 256 bits //string encrypted = _crypt.encrypt(password, key, iv); string decrypt = _crypt.decrypt(user.password, user.hashKey, user.vector); if (decrypt != password) { throw new Exception("Invalid Password"); } sessionId = this.CreateUserSession(companyId, user.id); if (status == UserStatus.ResetPassword) { this.UpdateStatus(user.id, UserStatus.Active); } ts.Complete(); } }
public dynamic initiateSpandanaTransaction(transactionModel obj) { dynamic objdata = new ExpandoObject(); try { obj.TYPE = "1"; obj.IP_ADDRESS = HttpContext.Current.Request.UserHostAddress; obj.SYS_NAME = System.Environment.MachineName; obj.TXN_ID = obj.SECRETRAINT_CODE + DateTime.Now.ToString("yymmddHHmm") + new Random().Next(1000, 9999); DataTable dt = transactionInsertion(obj); if (dt != null && dt.Rows.Count > 0) { string encrypttext = ""; string iv = ""; iv = CryptLib.GenerateRandomIV(16); string key = CryptLib.getHashSha256("GSWS TEST", 32); string obj2 = GetInputJsonFormat(obj); encrypttext = EncryptDecryptAlgoritham.EncryptStringAES(obj2, key, iv); objdata.status = 200; if (obj.URL_ID == "340200101") { objdata.URL = "https://www.spandana.ap.gov.in/gsws/servicegrievance_registration?accessToken=" + Token() + "&Volunteerid=2255667788&AadhaarNo=" + obj.UID + "&vvstype=VVS2&DistId=" + obj.Sdistcode + "&MandalId=" + obj.Smcode + "&GpId=" + obj.Svtcode + "&GpFlag=" + obj.SRuflag + "&encryptId=" + encrypttext + "&KEY=" + key + "&IV=" + iv; } else { objdata.URL = "https://www.spandana.ap.gov.in/gsws/servicerequest_registration?HodId=" + obj.SERVICE_CODE + "&accessToken= " + Token() + "&Volunteerid=2255667788&AadhaarNo=" + obj.UID + "&vvstype=VVS2&DistId=" + obj.Sdistcode + "&MandalId=" + obj.Smcode + "&GpId=" + obj.Svtcode + "&GpFlag=" + obj.SRuflag + "&encryptId=" + encrypttext + "&KEY=" + key + "&IV=" + iv; } objdata.Reason = "Record Inserted Successfully !!!"; } else { objdata.status = 400; objdata.Reason = "Failed to Insert Record, Please Try Again !!! "; } } catch (Exception ex) { objdata.status = 500; objdata.Reason = "Something Went Wrong.Please Try Again"; //ex.Message.ToString(); } return(objdata); }
public static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine("Hello World again 12!"); CryptLib _crypt = new CryptLib(); string plainText = "This is the text to be encrypted."; String iv = "4NAfcTL5nWERGSLl"; //CryptLib.GenerateRandomIV(16); //16 bytes = 128 bits string key = CryptLib.getHashSha256("my secret key", 32); //32 bytes = 256 bits String cypherText = _crypt.encrypt(plainText, key, iv); Console.WriteLine("isv=" + iv); Console.WriteLine("key=" + key); Console.WriteLine("Cypher text=" + cypherText); Console.WriteLine("Plain text =" + _crypt.decrypt(cypherText, key, iv)); }
public ActionResult ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { HumanResourceContext context = new HumanResourceContext(); Account result = context.AccountSet.Where(e => e.Email == model.Email).FirstOrDefault(); if (result == null) { return(View("ForgotPasswordConfirmation")); } else { string To = result.Email, UserID, Password, SMTPPort, Host; CryptLib cl = new CryptLib(); String key = CryptLib.getHashSha256("hrkey", 31); //32 bytes = 256 bit String em = CryptLib.GenerateRandomIV(16); //16 bytes = 128 bit string timeout = DateTime.Now.AddMinutes(30).ToString(); string emailtimeout = model.Email + "," + timeout; try { emailtimeout = cl.encrypt(emailtimeout, key, em); } catch { emailtimeout = ""; } var lnkHref = "<a href='" + Url.Action("ResetPassword", "UserLogin", new { param = emailtimeout, IV = em }, "http") + "'>Reset Password</a>"; //var lnkHref = "<a href='"+ Url.Action("ResetPassword", "UserLogin", new { param = emailtimeout, IV = em }) + "'>Reset Password</a>"; //HTML Template for Send email string subject = "Your changed password"; string body = "<html><body><b>You can reset your password here. </b><br/>" + lnkHref + "</body></html>"; //Get and set the AppSettings using configuration manager. AppSettings(out UserID, out Password, out SMTPPort, out Host); //Call send email methods. SendEmail(UserID, subject, body, To, UserID, Password, SMTPPort, Host); } } ViewBag.sendmessage = "Reset password link has been sent to your email."; return(View()); }
public void UpdateStatus(Guid userId, UserStatus status) { var data = this._repoUser.Find(userId); data.status = (int)status; if (status == UserStatus.ResetPassword) { CryptLib _crypt = new CryptLib(); string defaultPassword = GetSettingValue("DEFAULT_PASSWORD"); string hashShaKey = GetSettingValue("HRIS_HASHSHA_KEY"); string key = CryptLib.getHashSha256(hashShaKey, 31); //32 bytes = 256 bits string iv = CryptLib.GenerateRandomIV(16); string encrypted = _crypt.encrypt(defaultPassword, key, iv); data.password = encrypted; data.hashKey = key; data.vector = iv; } this._repoUser.Update(data); this._unitOfWork.Save(); }
public CryptHelper() { keySha256 = CryptLib.getHashSha256(key, 32); //32 bytes = 256 bits }
public dynamic initiateTransaction(transactionModel obj) { dynamic objdata = new ExpandoObject(); try { obj.TYPE = "1"; obj.IP_ADDRESS = HttpContext.Current.Request.UserHostAddress; obj.SYS_NAME = System.Environment.MachineName; obj.TXN_ID = obj.SECRETRAINT_CODE + DateTime.Now.ToString("yyMMddHHmm") + new Random().Next(1000, 9999); DataTable dt = transactionInsertion(obj); if (dt != null && dt.Rows.Count > 0) { string encrypttext = ""; string iv = ""; if (obj.TYPE_OF_SERVICE == "1") { iv = CryptLib.GenerateRandomIV(16); string key = CryptLib.getHashSha256("GSWS TEST", 32); string obj2 = GetInputJsonFormat(obj); encrypttext = EncryptDecryptAlgoritham.EncryptStringAES(obj2, key, iv); } else if (obj.URL_ID == "110401301" || obj.URL_ID == "110102501" || obj.URL_ID == "110102601" || obj.URL_ID == "310300104") { iv = CryptLib.GenerateRandomIV(16); string key = CryptLib.getHashSha256("GSWS TEST", 32); string obj2 = GetInputJsonFormat(obj); encrypttext = EncryptDecryptAlgoritham.EncryptStringAES(obj2, key, iv); } else if (obj.URL_ID == "200301401" || obj.URL_ID == "360201701" || obj.URL_ID == "360201401" || obj.URL_ID == "130101101" || obj.URL_ID == "280101201" || obj.URL_ID == "280101401" || obj.URL_ID == "280101301" || obj.URL_ID == "360201801" || obj.URL_ID == "3602018501" || obj.URL_ID == "170100102" || obj.URL_ID == "130101401" || obj.URL_ID == "130101501" || obj.URL_ID == "240200101") { iv = CryptLib.GenerateRandomIV(16); string key = CryptLib.getHashSha256("GSWS TEST", 32); string obj2 = GetInputJsonFormat(obj); encrypttext = EncryptDecryptAlgoritham.EncryptStringAES(obj2, key, iv); } else { } objdata.status = 200; //objdata.Translist = dt; objdata.encrypttext = encrypttext; objdata.key = iv; objdata.TransId = obj.TXN_ID; objdata.Reason = "Record Inserted Successfully !!!"; } else { objdata.status = 400; objdata.Reason = "Failed to Insert Record, Please Try Again !!! "; } } catch (Exception ex) { objdata.status = 500; objdata.Reason = "Something Went Wrong.Please Try Again"; //ex.Message.ToString(); } return(objdata); }
internal static string getIVkey() { return(CryptLib.getHashSha256(ConfigurationManager.AppSettings["IVKey"], 16)); }
public dynamic OrderDetails(paymentModel obj) { dynamic objdata = new ExpandoObject(); try { obj.orderId = "80120201019362644"; orderDetailsModel rootobj = new orderDetailsModel(); rootobj.Amount = obj.Amount; rootobj.Description = obj.Description; rootobj.mobileNumber = obj.mobileNumber; rootobj.orderId = obj.orderId; rootobj.totalAmount = obj.totalAmount; rootobj.TxnDate = obj.TxnDate; rootobj.userCharges = obj.userCharges; rootobj.userName = obj.userName; rootobj.walletType = ""; DataTable dt1 = gswsPaymentRequestProc(obj, "4", ""); obj.gswsCode = dt1.Rows[0][0].ToString(); obj.UniqueTxnId = obj.merchantId + obj.mobileNumber + DateTime.Now.ToString("yyyyMMddhhmmssmm"); string json = JsonConvert.SerializeObject(obj); string iv = CryptLib.GenerateRandomIV(16); string key = CryptLib.getHashSha256("GSWS TEST", 32); string encrypttext = EncryptDecryptAlgoritham.EncryptStringAES(json, key, iv); obj.encrypttext = encrypttext; obj.iv = iv; rootobj.encrypttext = obj.encrypttext; rootobj.iv = obj.iv; if (obj.gswsCode == "10690589" || obj.gswsCode == "10690588" || obj.gswsCode == "10690590" || obj.gswsCode == "21073101") { rootobj.walletType = "TA"; } else if (obj.gswsCode == "10690567" || obj.gswsCode == "10690568" || obj.gswsCode == "21073097" || obj.gswsCode == "21073098" || obj.gswsCode == "21073099") { rootobj.walletType = "WONE"; } else if (obj.gswsCode == "10690581" || obj.gswsCode == "10690561" || obj.gswsCode == "10690574" || obj.gswsCode == "10690572" || obj.gswsCode == "10690573" || obj.gswsCode == "10690582" || obj.gswsCode == "21073095" || obj.gswsCode == "21073096" || obj.gswsCode == "21073082" || obj.gswsCode == "21073083" || obj.gswsCode == "21073085" || obj.gswsCode == "21073088") { rootobj.walletType = "APW"; } DataTable dt = gswsPaymentRequestProc(obj, "1", ""); if (dt != null && dt.Rows.Count > 0) { token_gen.initialize(); token_gen.expiry_minutes = 60; token_gen.addClaim("admin"); token_gen.PRIMARY_MACHINE_KEY = "10101010101010101010101010101010"; token_gen.SECONDARY_MACHINE_KEY = "1010101010101010"; token_gen.addResponse("status", "200"); token_gen.addResponse("result", JsonConvert.SerializeObject(rootobj)); return(token_gen.generate_token()); } else { objdata.status = 400; objdata.result = "Invalid Input"; string mappath = HttpContext.Current.Server.MapPath("gswsPaymentRequestProc."); Task WriteTask = Task.Factory.StartNew(() => new Logdatafile().Write_ReportLog_Exception(mappath, JsonConvert.SerializeObject(obj))); } } catch (Exception ex) { objdata.status = 500; objdata.result = ex.Message.ToString(); } return(objdata); }
// save Services Url's public DataTable SaveServices_data_helper(InternalURL obj) { try { var comd = new OracleCommand(); comd.InitialLONGFetchSize = 1000; comd.CommandType = CommandType.StoredProcedure; comd.CommandText = "GSWS_IN_URL_MASTER"; comd.Parameters.Add("P_TYPE", OracleDbType.Varchar2).Value = obj.TYPE; comd.Parameters.Add("P_SD_ID", OracleDbType.Varchar2).Value = obj.DEPARTMENT; comd.Parameters.Add("P_HOD_ID", OracleDbType.Varchar2).Value = obj.HOD; comd.Parameters.Add("P_SCHEME_ID", OracleDbType.Varchar2).Value = obj.SERVICE; comd.Parameters.Add("P_TYPE_OF_REQUEST", OracleDbType.Varchar2).Value = obj.REQUESTTYPE; comd.Parameters.Add("P_URL_ID", OracleDbType.Varchar2).Value = obj.URL_ID; comd.Parameters.Add("P_URL", OracleDbType.Varchar2).Value = obj.URL; comd.Parameters.Add("P_URL_DESCRIPTION", OracleDbType.Varchar2).Value = obj.URLDESCRIPTION; comd.Parameters.Add("P_ACCESS_LEVEL", OracleDbType.Varchar2).Value = obj.ACCESSLEVEL; comd.Parameters.Add("P_DISTRICT_ID", OracleDbType.Varchar2).Value = obj.DISTRICT; comd.Parameters.Add("P_MANDAL_ID", OracleDbType.Varchar2).Value = obj.MANDAL; comd.Parameters.Add("P_GP_WARD_ID", OracleDbType.Varchar2).Value = obj.PANCHAYAT; comd.Parameters.Add("P_USER_NAME", OracleDbType.Varchar2).Value = obj.USERNAME; comd.Parameters.Add("P_PASSWORD", OracleDbType.Varchar2).Value = obj.PASSWORD; comd.Parameters.Add("P_ENCRYPT_PASSWORD", OracleDbType.Varchar2).Value = string.IsNullOrEmpty(obj.ENCRYPT_PASSWORD) ? null : CryptLib.getHashSha256(obj.ENCRYPT_PASSWORD, 31);; comd.Parameters.Add("P_TYPE_OF_SERVICE", OracleDbType.Varchar2).Value = obj.SERVICETYPE; comd.Parameters.Add("P_UR_FLAG", OracleDbType.Varchar2).Value = obj.RUFLAG; // comd.Parameters.Add("P_URL_DESC_TEL", OracleDbType.Varchar2).Value = obj.P_URL_DESC_TEL; comd.Parameters.Add("DESIGN_R", OracleDbType.Varchar2).Value = obj.RURALDESIGNATION; comd.Parameters.Add("DESIGN_U", OracleDbType.Varchar2).Value = obj.URBANDESIGNATION; comd.Parameters.Add("P_CUR", OracleDbType.RefCursor).Direction = ParameterDirection.Output; DataTable data = GetgswsDataAdapter(comd); if (data != null && data.Rows.Count > 0) { return(data); } else { return(null); } } catch (WebException wex) { string mappath = HttpContext.Current.Server.MapPath("ExceptionLogs"); Task WriteTask = Task.Factory.StartNew(() => new Logdatafile().Write_ReportLog_Exception(mappath, "Error Save Services URL data :" + wex.Message.ToString())); throw new Exception(wex.Message); } }