buf = System.Convert.FromBase64String(textBox3.Text.Trim());
string str=ASCIIEncoding.ASCII.GetString(rsa.Decrypt(buf,false)); wish u good luck
Greatsft
string str=ASCIIEncoding.ASCII.GetString(rsa.Decrypt(buf,false)); wish u good luck
Greatsft
解决方案 »
- 求教!!做一个答题界面!!!
- js解密
- windows services安装出错
- c#中如何系统时间的提取
- asp.net C# 三层中中得到存储过程output值的问题
- 网络上的XML文件无法读取,急!!!
- 如何在镶嵌的IE中做到这个功能?
- 用ExcuteReader(CommandBehavior.SingleResult)返回结果时,怎样在Reader中取值呀,用的是Access
- 求C# Windows Forms 程序设计(清华版)书的源程序.
- winform在textbox中显示不断追加的字符串时发生异常,怎么解决?
- 关于ascx,奇怪的问题!!
- 又关于ORACLE的LONG型字段操作的问题(100分)!
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
using System.Security.Cryptography;namespace 非对称加密
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.SaveFileDialog save;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.RichTextBox richtext2;
private System.Windows.Forms.OpenFileDialog open;
private System.Windows.Forms.RichTextBox richtext3;
private System.Windows.Forms.RichTextBox richtext;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
/// <summary>
/// 必需的设计器变量。
private static RSACryptoServiceProvider crypt;
private static string privatekey;
private static string publickey;
private static byte [] bytes;
private static string publicinfo;
private static string privateinfo;
private static string readpublickey;
private static string readprivatekey;
// ///private static byte [] onebytes ;
/// </summary>
private System.ComponentModel.Container components = null;
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.button6 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.richtext = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button8 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.richtext3 = new System.Windows.Forms.RichTextBox();
this.richtext2 = new System.Windows.Forms.RichTextBox();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.save = new System.Windows.Forms.SaveFileDialog();
this.open = new System.Windows.Forms.OpenFileDialog();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(8, 8);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(432, 224);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.button6);
this.tabPage1.Controls.Add(this.button3);
this.tabPage1.Controls.Add(this.button2);
this.tabPage1.Controls.Add(this.richtext);
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(424, 199);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "得到钥匙";
//
// button6
//
this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button6.Location = new System.Drawing.Point(340, 8);
this.button6.Name = "button6";
this.button6.TabIndex = 4;
this.button6.Text = "写入文件";
this.button6.Click += new System.EventHandler(this.button6_Click);
整体思想就是这样
加密::
static void Main()
{
//initialze the byte arrays to the public key information.
byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,191,178,56,
74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222,
207,137,149,173,14,92,120,206,222,158,28,40,24,30,16,175,
108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194,
240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139,
168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171,
38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93,
106,99,179,68,175,211,164,116,64,148,226,254,172,147}; byte[] Exponent = {1,0,1};
//Values to store encrypted symmetric keys.
byte[] EncryptedSymmetricKey;
byte[] EncryptedSymmetricIV; //Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Create a new instance of RSAParameters.
RSAParameters RSAKeyInfo = new RSAParameters(); //Set RSAKeyInfo to the public key values.
RSAKeyInfo.Modulus = PublicKey;
RSAKeyInfo.Exponent = Exponent; //Import key parameters into RSA.
RSA.ImportParameters(RSAKeyInfo); //Create a new instance of the RijndaelManaged class.
RijndaelManaged RM = new RijndaelManaged(); //Encrypt the symmetric key and IV.
EncryptedSymmetricKey = RSA.Encrypt(RM.Key, false);
EncryptedSymmetricIV = RSA.Encrypt(RM.IV, false);
}解密::
//Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();//Decrypt the symetric key and IV.
SymetricKey = RSA.Decrypt( EncryptedSymetricKey, false);
SymetricIV = RSA.Decrypt( EncryptedSymetricIV , false);
解密::
//Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();//Decrypt the symetric key and IV.
SymetricKey = RSA.Decrypt( EncryptedSymetricKey, false);
SymetricIV = RSA.Decrypt( EncryptedSymetricIV , false);在这段程序中,解密使用全新的RSACryptoServiceProvider实例,密钥是重新生成的,怎末能够解密呢?
你使用自己得私钥和公钥,然后利用例子里面得方式进行加密解密首先从文件中读取公钥和私钥的信息,然后看例子就可以了祝你好运http://www.vccode.com/file_list.php?type=62
谢谢你的回复,不过你没有看清题目,我只有E,N,D三个数字,你的例子中的私钥是包含了许多其他参数的!
如果大侠知道,请告知,我一定不吝分数
格式:3个 BASE64 string
任一把都可用来加密,另一把用来解密
公钥加密不比对称加密更安全
公钥加密并不能淘汰对称加密
公钥加密不会令密钥传送变得简单
实现:RSA,DSS
PKI,CARSA原理: 基于大因数分解的困难性
公钥m,n rm = 1mod(p-1)(q-1) n = pq
私钥p,q,r,p!=q p,q均为质数。R与(p-1)(q-1)
加密过程:a<n b = a^m mod n
解密过程:c = b^r mod pq (c = a) 如果第三者进行窃听时, 他会得到几个数: m, n(=pq), b
如果要解码的话, 必须得到 r所以, 必须对 n 作质因数分解 要防止分解, 最有效的方法是找两个非常的大质数 p, q, 使第三者作因数分解时发生困难
要是大哥找到答案了能不能也发给我一份呢?[email protected]谢谢了。
http://community.csdn.net/Expert/topic/3146/3146484.xml?temp=.1882593
也是和加密有关的