public static void ReadDoc(docFileModel docx) { ComponentInfo.SetLicense("FREE-LIMITED-KEY"); string encryptedText; //Чтение using (FileStream fs = new FileStream(Path.Combine(docx.Path, $"{docx.File.FileName}"), FileMode.Create)) { docx.File.CopyTo(fs); var document1 = DocumentModel.Load(fs); string text = document1.Content.ToString(); encryptedText = DeNcoder.Encrypt(text, docx.Key); } //Запись DocumentModel document = new DocumentModel(); document.Content.Delete(); document.Content.LoadText(encryptedText); document.Save(Path.Combine(docx.Path, $"{docx.File.FileName}")); }
public IActionResult docDecoder(docFileModel doc) { if (doc.File == null) { ModelState.AddModelError("File", "Файл не выбран."); return(View(doc)); } if (string.IsNullOrEmpty(doc.Key) || string.IsNullOrWhiteSpace(doc.Key)) { ModelState.AddModelError("Key", "Введите ключ."); return(View(doc)); } if (string.IsNullOrEmpty(doc.Path) || string.IsNullOrWhiteSpace(doc.Path)) { ModelState.AddModelError("Path", "Введите путь."); return(View(doc)); } string ext = Path.GetExtension(doc.File.FileName); string key = doc.Key; string path = doc.Path; if (!(ext == ".docx")) { ModelState.AddModelError("File", "Выбран файл неверного расширения."); return(View(doc)); } if (!DeNcoder.HasNotCyrillicChars(key)) { ModelState.AddModelError("Key", "Введён ключ с некиррилическими символами."); return(View(doc)); } if (!Directory.Exists(path)) { ModelState.AddModelError("Path", "Такой директории не существует"); return(View(doc)); } if (ModelState.IsValid) { WordReader.ReadDoc(doc); return(RedirectToAction("Index")); } return(View(doc)); }