buf = System.Convert.FromBase64String(textBox3.Text.Trim());
string str=ASCIIEncoding.ASCII.GetString(rsa.Decrypt(buf,false));                                   wish u good luck
                                            Greatsft

解决方案 »

  1.   

    using System;
    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;
      

  2.   

    public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
      

  3.   

    #region Windows 窗体设计器生成的代码
    /// <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);
      

  4.   

    呵呵,来点有用的吧,我在等ing
      

  5.   

    下面是在MSDN上找的,是针对对称算法的密钥进行加密解密。
    整体思想就是这样
    加密::
       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);
      

  6.   

    to: milkbb(李宇杰) ,你的例子不可能解密的,
    解密::
    //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实例,密钥是重新生成的,怎末能够解密呢?
      

  7.   

    不好意思,以上发言由于太多,CSDN不让我发完,干脆给你一个地址,
    你使用自己得私钥和公钥,然后利用例子里面得方式进行加密解密首先从文件中读取公钥和私钥的信息,然后看例子就可以了祝你好运http://www.vccode.com/file_list.php?type=62
      

  8.   

    to:Piyongcai(皮) 
    谢谢你的回复,不过你没有看清题目,我只有E,N,D三个数字,你的例子中的私钥是包含了许多其他参数的!
      

  9.   

    to:redbb(....Dotneter....) 
    如果大侠知道,请告知,我一定不吝分数
      

  10.   

    >>公钥(E,N),私钥(D)什么格式?数字?字母?文件?什么格式的文件?
      

  11.   

    to:idiotzeng(白痴) 
    格式:3个 BASE64 string
      

  12.   

    可以通过E,N,D构造RSACryptoServiceProvider
      

  13.   

    to: Piyongcai(皮) ,请不吝赐教,分不是问题!
      

  14.   

    I can give you some idea , I hope you can benifit from it : 公钥加密: 特点:使用了两把密钥,公钥和私钥,只知其一无法(很难)求出另一个。
        任一把都可用来加密,另一把用来解密
    公钥加密不比对称加密更安全
    公钥加密并不能淘汰对称加密
    公钥加密不会令密钥传送变得简单
    实现: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&nbsp;=&nbsp;a^m&nbsp;mod&nbsp;n 
    解密过程:c&nbsp;=&nbsp;b^r&nbsp;mod&nbsp;pq   (c = a)&nbsp;如果第三者进行窃听时,&nbsp;他会得到几个数:&nbsp;m,&nbsp;n(=pq),&nbsp;b
         如果要解码的话,&nbsp;必须得到&nbsp;r 所以,&nbsp;必须对&nbsp;n&nbsp;作质因数分解&nbsp; 要防止分解,&nbsp;最有效的方法是找两个非常的大质数&nbsp;p,&nbsp;q,&nbsp; 使第三者作因数分解时发生困难
      

  15.   

    天啊,我也在找这个问题的答案,快急死了.NET里RSACryptoServiceProvider类解密时的参数似乎一个都不能缺少。不过看来好像只能通过RSA算法中描述的那些参数的计算方法先自己计算出其余的参数了。要不就不能中这个类了吧?
    要是大哥找到答案了能不能也发给我一份呢?[email protected]谢谢了。
      

  16.   

    另请高手们关注一下这个帖子:
    http://community.csdn.net/Expert/topic/3146/3146484.xml?temp=.1882593
    也是和加密有关的