使用rsa算法加密... [英] encryption using rsa algorithm...
本文介绍了使用rsa算法加密...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该代码用于使用rsa算法加密任何字符串,因为unicode的值变为零,所以该代码未运行,请检查我的错误..
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]添加了代码块-OriginalGriff [/edit]
[edit]Code block added - OriginalGriff[/edit]
推荐答案
使用RSA加密的编程方式:
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();
这是CodeProject上有关使用C#进行RSA加密的文章:
C#.NET中的公钥RSA加密 [ ^ ]
This is an article on CodeProject about RSA encryption using C#:
Public Key RSA Encryption in C# .NET[^]
这篇关于使用rsa算法加密...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文