Click here to Skip to main content
14,692,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code is for enryption any string using rsa algorithm this code is not run because value of unicode become zero so check my mistake..

protected void Button1_Click(object sender, EventArgs e)
  {
      string ab;
      int unicode;
      ab = TextBox1.Text;

      foreach (char c in ab)
      {
           unicode = c;
          Console.WriteLine(unicode < 128 ? "ASCII:{0}" : "NON-ASCII:{0}", unicode);
          Response.Write(unicode);
      }

      Response.Write(unicode);
     Response.Write("Enter the value of p");
      double p=0,q=0,o=0;
      double d,c;
      string str = char.ConvertFromUtf32(unicode);
      Response.Write(str);
       p = (double)Convert.ToInt64(TextBox2.Text);
       q = (double)Convert.ToInt64(TextBox3.Text);


     /* if (!Int32.TryParse(TextBox2.Text, out p))
      {

      }
           if (!Int32.TryParse(TextBox3.Text, out q))
      {

      }*/

     double n = p * q;
     double q1 = (p - 1) * (q - 1);
          Response.Write(q1);

          o = (double)Convert.ToInt64(TextBox4.Text);
   /* if (!Int32.TryParse(TextBox4.Text, out o))
    {

    }*/
    d = (Math.Pow(0,-1)) % q1;
    c = (Math.Pow(this.unicode,n)) % n;

    Response.Write(c);
    unicode = (Math.Pow(c,d)) % n;
   Response.Write(this.unicode);
 //  Response.Write(unicode);
 string str = char.ConvertFromUtf32((int)unicode);
 // Response.Write(str);*/

       }


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 22-Sep-12 22:42pm
v2
Comments
OriginalGriff 23-Sep-12 3:45am
   
Good grief man, that code does nothing particularly useful, and certainly has nothing to do with RSA encryption.
For example, why are you sending the last character to your response string?
Why did you leave redundant comments in?
Why did you not format it properly - VS does that for you automatically.
Check your question - is it possible that you pasted a random lump of code, instead of the method you intended?

using encryption witg RSA programmaticaly:
System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
            System.Configuration.ConfigurationSection appSetting = config.GetSection("connectionStrings");
            if (appSetting.SectionInformation.IsProtected)
            {
                appSetting.SectionInformation.UnprotectSection();
                Label1.Text = " ConnectionString  is decrypted";
            }
            else
            {
                appSetting.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");//default used encription is DPAPI but if you want use RSA encryption use this one provider RsaProtectedConfigurationProvider
                Label1.Text = " ConnectionString  is encrypted";
            }
            config.Save();
   
This is an article on CodeProject about RSA encryption using C#:
Public Key RSA Encryption in C# .NET[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900