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 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 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 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)); } }
private string[] Transform(string file, string[] data) { String iv = ""; string key = ""; var application = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document document = application.Documents.Open(file); int count = document.Words.Count; string s2 = ""; for (int i = 1; i <= count; i++) { string text = document.Words[i].Text; s2 = s2 + text; } String cypherText = ""; if (data[0] == null) { iv = CryptLib.GenerateRandomIV(16); Random random = new Random(); key = getHashSha256(random.Next(6, 8).ToString(), 31); data[0] = iv; data[1] = key; } cypherText = Encrypt(s2, data[1], data[0]); document.Content.Text = cypherText; document.Close(true); application.Quit(true); return(data); }
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 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 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 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); }
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); }