public IActionResult Index(CipherViewModel model) { if (!ModelState.IsValid) { return(View(model)); } model.TextIn = model.ActionType == "Зашифровать" ? Encipher(model.TextIn, model.Shift) : Decipher(model.TextIn, model.Shift); ModelState.Clear(); return(View(model)); }
private void DoWork(CipherViewModel model, string direction, HttpFileCollectionBase files) { HttpPostedFileBase file; switch (direction) { case "Encryption": file = files[0]; if (file.ContentLength == 0) { throw new FileNotFoundException(); } model.Encrypt(file); model.SuccessResult = "File encrypted succesfully."; break; case "Decryption": file = files[1]; if (file.ContentLength == 0) { throw new FileNotFoundException(); } model.SuccessResult = model.Decrypt(file); break; case "Sign": file = files[0]; if (file.ContentLength == 0) { throw new FileNotFoundException(); } model.Sign(file); model.SuccessResult = "File signed succesfully."; break; case "Verify": file = files[1]; if (file.ContentLength == 0) { throw new FileNotFoundException(); } if (model.Verify(file)) { model.SuccessResult = "Verification is success"; } else { model.FileError = "Verification went wrong :("; } break; default: throw new MethodAccessException(); } }
public async Task <string> GetTotpAsync(CipherViewModel item) { string totp = null; var accessPremium = await _stateService.CanAccessPremiumAsync(); if (accessPremium || (item?.CipherView.OrganizationUseTotp ?? false)) { if (item != null && !string.IsNullOrWhiteSpace(item.Totp)) { totp = await _totpService.GetCodeAsync(item.Totp); } } return(totp); }
private string GetTotp(CipherViewModel item) { string totp = null; if (_isPremium) { if (item != null && !string.IsNullOrWhiteSpace(item.Totp.Value)) { totp = App.Utilities.Crypto.Totp(item.Totp.Value); } } return(totp); }
public string GetTotp(CipherViewModel item) { string totp = null; if (_accessPremium) { if (item != null && !string.IsNullOrWhiteSpace(item.Totp.Value)) { totp = Crypto.Totp(item.Totp.Value); } } return(totp); }
public ActionResult Index(CipherViewModel model, string cryptDirection, string signDirection, string download, string hash, string Method_Encryption_Sign, string Method_Decryption_Verify) { try { if (!string.IsNullOrEmpty(download) && !string.IsNullOrEmpty(model.Filename)) { ViewBag.Tab = download; var stream = new FileStream(model.Filename, FileMode.Open, FileAccess.Read); return(new FileStreamResult(stream, "text/plain")); } if (!string.IsNullOrEmpty(hash)) { ViewBag.Tab = hash; model.CalculateHash(); } else { var direction = string.IsNullOrEmpty(cryptDirection) ? signDirection : cryptDirection; ViewBag.Tab = direction; var method = (direction == "Encryption" || direction == "Sign") ? Method_Encryption_Sign : Method_Decryption_Verify; model.Crypto = GetCryptoMethod(method); DoWork(model, direction, Request.Files); } } catch (Exception e) { if (e.Source == "Virgil.Crypto") { model.FileError = "Don't cheat. It's bulletproof :)"; } else { model.FileError = e.Message; } } return(View(model)); }
public TabbedPage1(Cipher_Type cipherType) { InitializeComponent(); cipher = new CipherViewModel(cipherType); // Bind Cipher ViewModel object to tabbed page this.BindingContext = cipher; // Set IsBusy to false on inital page load. cipher.IsBusy = false; // Set page elements based on Cipher type switch (cipher.Type) { case Cipher_Type.Caesar: Input_Key.Keyboard = Keyboard.Numeric; Input_Key.MaxLength = 2; break; case Cipher_Type.Hill: Input_Key.MaxLength = 4; break; case Cipher_Type.Homophonic: Input_Key.Text = "21,27,31,40;15;01,33;20,34;22,28,32,36,37;05;17;14;02,29,38,41;19;03;07,39,42;09,43;12,48,97;18,60,85;26,44;25;24,49;10,30,45,99;06,96,55;16,94;23;13;11;08;04;"; break; case Cipher_Type.Monoalphabetic: break; case Cipher_Type.Vernam: Input_Key.IsVisible = false; break; case Cipher_Type.Vigenere: break; } }
public MainWindow() { DataContext = new CipherViewModel(); InitializeComponent(); }