日期:2011-05-13  浏览次数:20412 次

C#—非对称加密:加密文件
★★★★★★ ☆☆☆ ★★★★★★
●●○○     聂永     ○○●●
§§§§nie_yong@163.com§§§§
◆◆□□nie.yong@126.com□□◆◆
№№№№№№ ※※※ №№№№№№   
说明:
1.你要注意的是读取文件的两种不同方式;
2.从已经保存的钥匙文件中读取其内容;
3.这个程序做的很粗糙(要准备考外语六级,要准备期末考试,实在很忙啊!),希望诸位能够完善,然后也发表出来,在下表示感谢;
4.参考书目: 《C#数据安全手册》;
5.有做这方面程序的朋友,愿意相交。
代码部分:

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

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.TabPage tabPage3;
  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.Label label2;
  private System.Windows.Forms.RichTextBox richtext2;
  private System.Windows.Forms.OpenFileDialog open;
  private System.Windows.Forms.Label label3;
  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;
  private System.Windows.Forms.TextBox textBox2;
  private System.Windows.Forms.Label label4;
  private System.Windows.Forms.Button button9;
  private System.Windows.Forms.TextBox textBox3;
  private System.Windows.Forms.Label label5;
  private System.Windows.Forms.Button button10;
  private System.Windows.Forms.Label label6;
  private System.Windows.Forms.Button button11;
  private System.Windows.Forms.Button button12;
  private System.Windows.Forms.RichTextBox richtext4;
  private System.Windows.Forms.Button button13;
  private System.Windows.Forms.Button button14;
  private System.Windows.Forms.Button button15;
  private System.Windows.Forms.TabPage tabPage4;
  private System.Windows.Forms.TextBox textBox4;
  private System.Windows.Forms.Button button16;
  private System.Windows.Forms.TextBox textBox5;
  private System.Windows.Forms.Button button17;
  private System.Windows.Forms.Button button18;
  private System.Windows.Forms.Button button19;
  private System.Windows.Forms.Button button20;
  private System.Windows.Forms.Button button21;
  private System.Windows.Forms.RichTextBox richtext5;
  /// <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 bool openla = false;
  private bool savela = false