Пример #1
0
        public ActionResult RSA(RSAViewModel model)
        {
            RSAViewModel viewModel = RSAUtility.rsa2(model);

            ModelState.Clear();
            return(View(viewModel));
        }
Пример #2
0
        // GET: RSA/Create
        public ActionResult GenerarLlaves(string primo1, string primo2)
        {
            RSAViewModel rsa = new RSAViewModel();

            rsa.ValorP = Convert.ToInt32(primo1);
            rsa.ValorQ = Convert.ToInt32(primo2);
            return(View(rsa));
        }
Пример #3
0
        public RSAView()
        {
            Initialized += delegate
            {
                History.Document.Blocks.Clear();
                viewModel         = (RSAViewModel)DataContext;
                viewModel.History = History;
                viewModel.GenerateNewRSA((int)scrollBar.Value);
                message.Text = Languages.defaultMessageRSA;
            };

            InitializeComponent();
        }
Пример #4
0
 public async Task RSAGenerate(string message)
 {
     try
     {
         var model = new RSAViewModel();
         model.PlainText = message;
         var result = RSAUtility.rsa2(model);
         await Clients.All.SendAsync("ReceiveMessage", result);
     }
     catch
     {
         await Clients.All.SendAsync("ReceiveMessage", "Invalid input");
     }
 }
Пример #5
0
 public ActionResult GenerarLlaves(RSAViewModel rsa)
 {
     try
     {
         if (ModelState.IsValid && rsa.ValorP > 0 && rsa.ValorQ > 0)
         {
             if (rsa.ValorP == 1 || rsa.ValorQ == 1)
             {
                 return(View(rsa));
             }
             else
             {
                 var primo1 = numeroPrimo(rsa.ValorP, 2);
                 var primo2 = numeroPrimo(rsa.ValorQ, 2);
                 if (primo1 == true && primo2 == true)
                 {
                     if (rsa.ValorP * rsa.ValorQ < 255)
                     {
                         ViewBag.Message = "Please verify the multiplication of p*q is greater than 256";
                         return(View(rsa));
                     }
                     else
                     {
                         FilePath = Server.MapPath("~/Archivo");
                         CifradoRSA RSA = new CifradoRSA();
                         RSA.GenerarLlaves(rsa.ValorP, rsa.ValorQ, FilePath);
                         return(RedirectToAction(nameof(LlavesGeneradas)));
                     }
                 }
                 else
                 {
                     ViewBag.Message = "Please verify the numbers are prime";
                     return(View(rsa));
                 }
             }
         }
         else
         {
             ViewBag.Message = "Please verify the number is greater than 0";
             return(View(rsa));
         }
     }
     catch
     {
         return(View());
     }
 }
 public static RSAViewModel rsa2(RSAViewModel model)
 {
     try
     {
         RSACryptoServiceProvider cryptoServiceProvider = new RSACryptoServiceProvider(1024);
         RSAParameters            parameters1           = cryptoServiceProvider.ExportParameters(false);
         RSAParameters            parameters2           = cryptoServiceProvider.ExportParameters(true);
         model.PublicKey  = "e=" + RSAUtility.ByteToString(parameters1.Exponent) + Environment.NewLine + "n=" + RSAUtility.ByteToString(parameters1.Modulus);
         model.PrivateKey = "d=" + RSAUtility.ByteToString(parameters2.D) + Environment.NewLine + "n=" + RSAUtility.ByteToString(parameters1.Modulus);
         cryptoServiceProvider.ImportParameters(parameters1);
         byte[] numArray = cryptoServiceProvider.Encrypt(RSAUtility.StringToByte(model.PlainText), true);
         model.CipherText = RSAUtility.ByteToString(numArray);
         cryptoServiceProvider.ImportParameters(parameters2);
         byte[] decryptedData = cryptoServiceProvider.Decrypt(numArray, true);
         model.DecryptedText = RSAUtility.ByteToAscii(decryptedData);
     }
     catch (CryptographicException ex)
     {
     }
     return(model);
 }
Пример #7
0
        public ActionResult RSA()
        {
            RSAViewModel model = new RSAViewModel();

            return(View(model));
        }