通过File文件类的加密和解密文件
2007-12-30 14:45
309 查看
通过File文件类的加密和解密文件主要是对IO命名空间中的文件类的Encrpty和Decrpty方法的使用。
源代码如下: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;
using System.Diagnostics;
namespace FileCryptographic
{
public partial class Form1 : Form
{
public string sourceFile="C://Test.txt";
public Form1()
{
InitializeComponent();
}
private void btnEncry_Click(object sender, EventArgs e)
{
try
{
File.Encrypt(sourceFile);
this.richTextBox1.Text = File.ReadAllText(sourceFile);
Process.Start("explorer.exe", "C://");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
//throw;
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.txtPosition.Text = this.openFileDialog1.FileName;
sourceFile=this.txtPosition.Text;
/*
using (FileStream fs = new FileStream(sourceFile, FileMode.Open))
{
BufferedStream bs = new BufferedStream(fs);
StreamReader sr = new StreamReader(bs);
this.richTextBox1.Text = sr.ReadToEnd();
}
*/
}
}
private void btnDecry_Click(object sender, EventArgs e)
{
try
{
File.Decrypt(sourceFile);
this.richTextBox1.Text = File.ReadAllText(sourceFile);
Process.Start("explorer.exe", "C://");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
//throw;
}
}
private void Form1_Load(object sender, EventArgs e)
{
File.WriteAllText(sourceFile, Properties.Resources.test, Encoding.UTF8);
this.richTextBox1.Text = File.ReadAllText(sourceFile);
Process.Start("explorer.exe", "C://");
}
}
}
源代码如下: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;
using System.Diagnostics;
namespace FileCryptographic
{
public partial class Form1 : Form
{
public string sourceFile="C://Test.txt";
public Form1()
{
InitializeComponent();
}
private void btnEncry_Click(object sender, EventArgs e)
{
try
{
File.Encrypt(sourceFile);
this.richTextBox1.Text = File.ReadAllText(sourceFile);
Process.Start("explorer.exe", "C://");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
//throw;
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.txtPosition.Text = this.openFileDialog1.FileName;
sourceFile=this.txtPosition.Text;
/*
using (FileStream fs = new FileStream(sourceFile, FileMode.Open))
{
BufferedStream bs = new BufferedStream(fs);
StreamReader sr = new StreamReader(bs);
this.richTextBox1.Text = sr.ReadToEnd();
}
*/
}
}
private void btnDecry_Click(object sender, EventArgs e)
{
try
{
File.Decrypt(sourceFile);
this.richTextBox1.Text = File.ReadAllText(sourceFile);
Process.Start("explorer.exe", "C://");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
//throw;
}
}
private void Form1_Load(object sender, EventArgs e)
{
File.WriteAllText(sourceFile, Properties.Resources.test, Encoding.UTF8);
this.richTextBox1.Text = File.ReadAllText(sourceFile);
Process.Start("explorer.exe", "C://");
}
}
}
相关文章推荐
- C#通过一个密码对文件进行加密解密操作
- 有关java对压缩文件的加密(通过密码解密)
- JAVA中使用RSA通过秘钥文件对字符串进行加密解密
- c# 通过修改图片对象的文件的字节 变相"加密""解密"图片在磁盘的存储
- c# 通过修改图片对象的文件的字节 变相"加密""解密"图片在磁盘的存储
- 通过IO流对文件进行加密和解密
- android ndk 05 C语言 _union_enum 联合体 枚举 IO文件操作(文件加密解密)
- ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
- java spring中对properties属性文件加密及其解密
- java spring中对properties属性文件加密及其解密
- 在R12下加载Java Bean,配置FORMS_WEB_CONFIG_FILE文件/通过AutoConfig实现Form Server配置文件的修改
- node 加密音频文件 和 解密音频文件
- 如何使用 Visual C# 加密和解密文件
- [转]C# 使用 256 位 AES 加密和解密文件
- Delphi 实现加密与解密文件
- 利用TEA算法实现加密密码文件生成与解密
- xml文件加密上传和sftp下载解密基本思路
- 使用input file 通过ajax 上传文件中onChange事件只触发一次问题
- kettle生成ktr文件_数据库密码的加密与解密
- 通过RandomAccessFile实现一份文件存储多个对象再拿出来