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("전체 복호화 완료"); }
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")); } }