对一个件加密和解密的一个简单方法

还在为你的隐私文件被别人看而烦恼吗?我们程序员自己可以做一个像加密解密这样的软件,下面就是源码(利用了流的技术和缓存技术)

只需要单击浏览你所要加密的文件

 

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;
          
        }

      
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值