5
Answers

whats the problem in the running? rsa code

rooholah heydari

rooholah heydari

8y
450
1
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. using System.Security.Cryptography;  
  9.   
  10. namespace RSAEncryption  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.         private void Form1_Load(object sender, EventArgs e)  
  19.         {  
  20.               
  21.         }  
  22.  
  23.         #region-----Encryptionand Decryption Function-----  
  24.         static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)  
  25.         {  
  26.             try  
  27.             {  
  28.                 byte[] encryptedData;  
  29.                 using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())  
  30.                 {  
  31.                     RSA.ImportParameters(RSAKey);  
  32.                     encryptedData = RSA.Encrypt(Data, DoOAEPPadding);  
  33.                 }  
  34.                 return encryptedData;  
  35.             }  
  36.             catch (CryptographicException e)  
  37.             {  
  38.                 Console.WriteLine(e.Message);  
  39.   
  40.                 return null;  
  41.             }  
  42.   
  43.         }  
  44.   
  45.         static public byte[] Decryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)  
  46.         {  
  47.             try  
  48.             {  
  49.                 byte[] decryptedData;  
  50.                 using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())  
  51.                 {  
  52.                     RSA.ImportParameters(RSAKey);  
  53.                     decryptedData = RSA.Decrypt(Data, DoOAEPPadding);  
  54.                 }  
  55.                 return decryptedData;  
  56.             }  
  57.             catch (CryptographicException e)  
  58.             {  
  59.                 Console.WriteLine(e.ToString());  
  60.   
  61.                 return null;  
  62.             }  
  63.   
  64.         }  
  65.         #endregion  
  66.  
  67.         #region--variables area  
  68.         UnicodeEncoding ByteConverter = new UnicodeEncoding();  
  69.         RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();  
  70.         byte[] plaintext;  
  71.         byte[] encryptedtext;  
  72.         #endregion  
  73.  
  74.         #region-- Function Implemantation  
  75.         private void button1_Click(object sender, EventArgs e)  
  76.         {  
  77.             plaintext = ByteConverter.GetBytes(txtplain.Text);  
  78.             encryptedtext = Encryption(plaintext, RSA.ExportParameters(false), false);  
  79.             txtencrypt.Text = ByteConverter.GetString(encryptedtext);  
  80.   
  81.         }  
  82.         private void button2_Click(object sender, EventArgs e)  
  83.         {  
  84.             byte[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(true), false);  
  85.             txtdecrypt.Text = ByteConverter.GetString(decryptedtex);  
  86.         }  
  87.         #endregion  
  88.     }  
  89. }  
Error 1 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) E:\asli\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs 18 33 WindowsFormsApplication1
 

Answers (5)