public void ShouldEncryptAndDecryptPasswordWhenRight() { string hashedpassword0 = Convert.ToBase64String(AESHelper.EncryptString("abcd", user.Password)); string password0 = AESHelper.DecryptToString(Convert.FromBase64String(hashedpassword0), user.Password); Assert.Equal("abcd", password0); }
public IActionResult Add() { if (ModelState.IsValid) { Passwd.UserId = Functions.getUser(_cache).Id; // get logged user var masterPassword = _cache.Get(CacheNames.masterPassword).ToString(); // get current user masterpassword var encrypted = AESHelper.EncryptString(Passwd.Password, masterPassword); // encrypt with masterpassword Passwd.Password = Convert.ToBase64String(encrypted); // add encypted password as a string to variable _db.Passwds.Add(Passwd); // add var to database ActionType actionType = new ActionType() { Action = "Add password to database", UserId = Passwd.UserId, Time = DateTime.Now }; Functions.AddActionToDatabase(_db, actionType); _db.SaveChanges(); // save database return(RedirectToAction("Index")); } return(View(Passwd)); }
private void Button_Click_Encrypt(object sender, RoutedEventArgs e) { try { AesText.Text = AESHelper.EncryptString(AesText.Text, AESHelper.Key128);; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static string GetUpdateUpData(UpdateUpInfo info) { try { string key = "AwEAAdidHa6npFP1kbXvgITJ+mXzUHTkQVABzOyfpmesYhefJG8vkFm9LlrAX7J4n/X6eLuTEvO41kQ0XKkdOKPT+YMddx4GK2R5CYs41l4DdWarp4AFyUY5XqFyVnpT3Db6uzzvI+Haw0jaeUynaPykNOIcmaDDHP84ZLGNoIOUG5Pj"; string source = JsonHelper.SerializeObject(info); return(AESHelper.EncryptString(source, key)); } catch { return(""); } }
public IActionResult Edit() { var password = _db.Passwds.Where(a => a.Id == Passwd.Id).FirstOrDefault(); if (password.UserId == Functions.getUser(_cache).Id) { if (ModelState.IsValid) { var oldPassword = password.Password; var masterPassword = _cache.Get(CacheNames.masterPassword).ToString(); // get current user masterpassword var encrypted = AESHelper.EncryptString(Passwd.Password, masterPassword); // encrypt with masterpassword password.Password = Convert.ToBase64String(encrypted); // add encypted password as a string to variable password.WebAddress = Passwd.WebAddress; password.Login = Passwd.Login; ActionType actionType = new ActionType() { Action = "Edit password id=" + password.Id, UserId = password.UserId, Time = DateTime.Now }; Functions.AddActionToDatabase(_db, actionType); PasswdHistory passwdHistory = new PasswdHistory() { NewPasswd = password.Password, OldPasswd = oldPassword, Time = DateTime.Now, UserId = password.UserId, PasswdId = password.Id }; Functions.AddHistoryToDatabase(_db, passwdHistory); _db.SaveChanges(); // save database return(RedirectToAction("Index")); } return(View(Passwd)); } _cache.Set(CacheNames.error4, "You are not the owner"); return(RedirectToAction("Index")); }
static void Main(string[] args) { string sss = string.Empty; sss = sss.ToUpper(); Guid g = Guid.Empty; Guid st; Guid.TryParse("", out st); if (st == g) { int d = 100; } string dd = st.ToString(); // AddCookie:userid=1c5c92092f73437f8237f480cbff5c6f,SecretToken=451f7e73b80e4ab7b82d0391ca11c046 string showText = "uhKre535fW3s%2BgrntACvHFAXvaELKiA6wuNk5z1q8sv%2FBQRg1%2FL88F8FfdmwgwK3"; string uid2 = "1c5c92092f73437f8237f480cbff5c6f"; string code = "451f7e73b80e4ab7b82d0391ca11c046"; string ss = AESHelper.EncryptString(uid2, code); string uid = AESHelper.DecryptString(ss, code); }