private void Decrypt_Click(object sender, RoutedEventArgs e) { foreach (string item in File2.GetDirectories(root: "", path, rootDir + Global.DownloadFolder)) { if (File.Exists($"{path}/info.json")) { JObject j = JObject.Parse(File.ReadAllText($"{path}/info.json")); j["encrypted"] = false; File.WriteAllText($"{path}/info.json", j.ToString()); } string[] files = Directory.GetFiles(item); foreach (string file in files) { try { byte[] org = File.ReadAllBytes(file); byte[] enc = FileDecrypt.Default(org); File.Delete(file); File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file)), enc); } catch { } } } MessageBox.Show("전체 복호화 완료"); }
private void Decrypt_Click(object sender, RoutedEventArgs e) { bool err = FileDecrypt.TryFiles(h.dir); if (err) { while (true) { InputBox box = new InputBox("비밀번호를 입력해주세요.", "비밀번호가 맞지 않습니다.", ""); string password = box.ShowDialog(); if (box.canceled) { return; } if (FileDecrypt.TryFiles(h.dir, SHA256.Hash(password), excepts: new string[] { ".txt", ".json" })) { break; } } } h.thumb = ImageProcessor.ProcessEncrypt(File2.GetImages(h.dir).First()); h.files = h.files.Select(x => Path.Combine(Path.GetDirectoryName(x), Path.GetFileNameWithoutExtension(x))).ToArray(); h.encrypted = false; thumbNail.Source = h.thumb; thumbNail.ToolTip = GetToolTip(panel.Height); Process.Start(h.dir); }
public static BitmapImage ProcessEncrypt(string url) { if (url.isUrl()) { if (url.EndsWith(".webp")) { return(LoadWebPImage(url)); } else { return(LoadWebImage(url)); } } else if (Global.FileEn) { try { byte[] org = File.ReadAllBytes(url); byte[] dec = FileDecrypt.Default(org); using (var ms = new MemoryStream(dec)) { var image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; // here image.StreamSource = ms; image.EndInit(); return(image); } } catch { try { return(LoadMemory(url)); } catch (FileNotFoundException) { return(FromResource("NoImage.jpg")); } catch (NotSupportedException) { return(FromResource("ErrEncrypted.jpg")); } } } else { try { return(LoadMemory(url)); } catch (FileNotFoundException) { return(FromResource("NoImage.jpg")); } catch (NotSupportedException) { return(FromResource("ErrEncrypted.jpg")); } } }
private void ChangePassword_Click(object sender, RoutedEventArgs e) { Config cfg = new Config(); JObject config = cfg.Load(); List <string> decs = new List <string>(); foreach (string item in Directory.GetDirectories(Global.MainWindow.path)) { string[] files = Directory.GetFiles(item); foreach (string file in files) { try { byte[] org = File.ReadAllBytes(file); byte[] enc = FileDecrypt.Default(org); File.Delete(file); File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file)), enc); decs.Add(Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file))); } catch { } } } MessageBox.Show("복호화 완료"); config["pw"] = SHA256.Hash(new InputBox("비밀번호를 입력해주세요.", "비밀번호 설정", "").ShowDialog()); cfg.Save(config); foreach (string file in decs) { if (Path.GetFileName(file) == "info.json") { continue; } if (Path.GetFileName(file) == "info.txt") { continue; } if (Path.GetExtension(file) == ".lock") { continue; } byte[] org = File.ReadAllBytes(file); byte[] enc = Scripts.FileEncrypt.Default(org); File.Delete(file); File.WriteAllBytes(file + ".lock", enc); } MessageBox.Show("암호화 완료"); }
public static async Task <byte[]> ProcessAsync(string url) { if (url.isUrl()) { if (url.EndsWith(".webp")) { return(await LoadUrlWebPImageAsync(url)); } else { return(await LoadUrlImageAsync(url)); } } else if (Global.config.file_encrypt.Get <bool>()) { try { byte[] org = File.ReadAllBytes(url); byte[] dec = FileDecrypt.Default(org); return(dec); } catch { } } try { return(LoadFile(url)); } catch (FileNotFoundException) { return(FromResource("NoImage.jpg")); } catch (NotSupportedException) { return(FromResource("ErrEncrypted.jpg")); } }
public void ProcessRequest(HttpContext context) { context.Response.Buffer = true; context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); context.Response.AddHeader("pragma", "no-cache"); context.Response.AddHeader("cache-control", ""); context.Response.CacheControl = "no-cache"; context.Response.ContentType = "text/plain"; string strUserName = StringClass.EncodeString(context.Request.Form["txtUserName"].Trim()); string strOldPwd = StringClass.EncodeString(context.Request.Form["txtUserPwd"]); string strUserPwd = StringClass.EncryptPassword(context.Request.Form["txtUserPwd"], StringClass.PasswordFormat.MD5_32); bool IsRemember = context.Request.Form["remember"] != null ? true : false; if (String.IsNullOrEmpty(strUserName)) { context.Response.Write("Please enter your email as user name!"); return; } else { strUserName = StringClass.RemoveSQL(strUserName.ToLower()); } if (String.IsNullOrEmpty(strOldPwd)) { context.Response.Write("Please enter your password!"); return; } else { strUserPwd = StringClass.EncryptPassword(strOldPwd, StringClass.PasswordFormat.MD5_32).ToLower(); } if (context.Session["ValidateCode"] != null) { if (context.Request.Form["txtUserVal"].Trim() != context.Session["ValidateCode"].ToString()) { context.Response.Write("Validation Code is not correct!"); return; } } string error = ""; Model.t_log_login loginLog = new Model.t_log_login(); loginLog.ID = Guid.NewGuid().ToString().ToLower(); loginLog.LoginDate = DateTime.Now; loginLog.IPAddress = context.Request.ServerVariables["REMOTE_ADDR"] != null ? context.Request.ServerVariables["REMOTE_ADDR"].Trim() : ""; loginLog.ClientInfo = context.Request.ServerVariables["Http_User_Agent"]; Model.t_rol_user user = (new BLL.t_rol_user()).Login(strUserName, strUserPwd, loginLog); if (user != null && user.Password.ToLower() == strUserPwd.ToLower()) { if (user.IsValid > 0) { try { HttpCookie Cookie = new HttpCookie("UserCookie"); if (IsRemember) { Cookie.Expires = DateTime.Now.AddDays(7); } else { Cookie.Expires = DateTime.Now.AddDays(-1); } Random ra = new Random(); string cookieValue = FileDecrypt.Encrypt(user.ID + "&" + user.Username, "", ra); Cookie.Values.Add("cookieValue", cookieValue); context.Response.Cookies.Add(Cookie); } catch { } } else { error = "This user has been disabled!"; context.Response.Write(error); return; } context.Session["User"] = user; } else { error = "Your username or passowrd is incorrect!"; context.Response.Write(error); return; } string roleName = ""; BLL.t_rol_role roleBll = new BLL.t_rol_role(); DataSet roleNameDS = roleBll.GetRoleNameByRoleID(user.RoleID); if (roleNameDS.Tables[0].Rows.Count != 0) { roleName = roleNameDS.Tables[0].Rows[0]["RoleName"].ToString(); } else { context.Response.Write("Failed to get the role."); } if (roleName == "System Administrator") { context.Response.Write("<script language='javascript'>window.location.href='/../Views/Admin/index.aspx';</script>"); } if (roleName == "User") { user = null; loginLog = null; context.Response.Write("<script language='javascript'>window.location.href='/../Views/index.aspx';</script>"); } }