c#加密文件只可以对文件本身加密,却不能对文件夹加密,经查询得知:是系统限制了,不知道真假,大家可在查询,把结果告诉大家共享。其实系统已经集成了对文件夹和硬盘的加密的功能。下面是对单个文件的加密代码:
引用中主要是添加了两个:using System.Security.Cryptography; using System.IO;
源码(带有详细的注释):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
namespace xiaoxia
{
public partial class FileJiami : Form
{
public FileJiami()
{
InitializeComponent();
}
private void FileJiami_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//文件浏览
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.txtFileIn.Text = this.openFileDialog1.FileName;
this.txtFileOut.Text = "填写名称和后缀";
}
}
private void button2_Click(object sender, EventArgs e)
{