还在为你的隐私文件被别人看而烦恼吗?我们程序员自己可以做一个像加密解密这样的软件,下面就是源码(利用了流的技术和缓存技术)
只需要单击浏览你所要加密的文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 文件的加密解密
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
FileInfo fileinfo = new FileInfo(txtSourse.Text);
using(FileStream outFile=new FileStream(txtTarget.Text,FileMode.Create))
{
using(FileStream sourseFile=new FileStream (txtSourse.Text,FileMode.Open))
{
byte[] bytes=new byte[1024*1024*4];
int readCount=0;
while((readCount=sourseFile.Read(bytes,0,bytes.Length))>0)
{
for (int i = 0; i < readCount; i++)
{
bytes [i]= (byte)(byte.MaxValue - bytes[i]);
}
outFile.Write(bytes, 0, readCount);
}
MessageBox.Show("加密或解密成功!");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog()!=DialogResult.OK)
{
return;
}
txtSourse.Text = openFileDialog1.FileName;
}
}
}