public static RSAViewModel rsa2(RSAViewModel model) { try { int keySize = 1024; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(keySize); RSAParameters publickey = rsa.ExportParameters(false); // don't export private key RSAParameters privatekey = rsa.ExportParameters(true); // export private key //\b 123\b0 model.PublicKey = "e=" + ByteToString(publickey.Exponent) + Environment.NewLine + "n=" + ByteToString(publickey.Modulus); model.PrivateKey = "d=" + ByteToString(privatekey.D) + Environment.NewLine + "n=" + ByteToString(publickey.Modulus); rsa.ImportParameters(publickey); byte[] encryptedData = rsa.Encrypt(StringToByte(model.PlainText), true); model.CipherText = ByteToString(encryptedData); rsa.ImportParameters(privatekey); byte[] decryptedData = rsa.Decrypt(encryptedData, true); model.DecryptedText = ByteToAscii(decryptedData); } catch (CryptographicException ex) { } return(model); }
public static RSAViewModel rsa2(RSAViewModel model) { try { int keySize = 1024; RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(keySize); RSAParameters publickey = rsa.ExportParameters(false); // don't export private key RSAParameters privatekey = rsa.ExportParameters(true); // export private key //\b 123\b0 model.PublicKey = "e=" + ByteToString(publickey.Exponent) + Environment.NewLine + "n=" + ByteToString(publickey.Modulus); model.PrivateKey = "d=" + ByteToString(privatekey.D) + Environment.NewLine + "n=" + ByteToString(publickey.Modulus); rsa.ImportParameters(publickey); byte[] encryptedData = rsa.Encrypt(StringToByte(model.PlainText), true); model.CipherText=ByteToString(encryptedData); rsa.ImportParameters(privatekey); byte[] decryptedData = rsa.Decrypt(encryptedData, true); model.DecryptedText = ByteToAscii(decryptedData); } catch (CryptographicException ex) { } return model; }
public ActionResult RSA(RSAViewModel model) { RSAViewModel viewModel = RSAUtility.rsa2(model); ModelState.Clear(); return View(viewModel); }
public ActionResult RSA() { RSAViewModel model = new RSAViewModel(); return View(model); }