資源簡介
c#文件夾及文件加密,本代碼重點在怎么遞歸建立文件夾及其中的文件實施加密,加密算法網上一大堆,我就不特別弄了。不懂的請留言。可能下載分比較高,但是也是自己想了很久才弄出來的,所以得點分也會高興高興有動力- -。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Data;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;
namespace?_2014年8月4日IO流
{
????public?partial?class?Form1?:?Form
????{
????????bool?isErr?=?false;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????#region?判斷是否含有字符串加/解密
????????public?string?GetName(string?fileName)
????????{
????????????if?(fileName.Contains(“【已加密】“))
????????????{
????????????????return?fileName.Substring((“【已加密】“).Length?fileName.Length?-?(“【已加密】“).Length);
????????????}
????????????else?if?(fileName.Contains(“【已解密】“))
????????????{
????????????????return?fileName.Substring((“【已解密】“).Length?fileName.Length?-?(“【已解密】“).Length);
????????????}
????????????else
????????????????return?fileName;
????????}?
????????#endregion
????????#region?加密解密文件/文件夾事件
????????private?void?btnJiaMi_Click(object?sender?EventArgs?e)
????????{
????????????Button?btn?=?sender?as?Button;
????????????string?currentBtnName?=?btn.Name;
????????????string?alreadyDone;
????????????string?srcPath;
??????????
????????????if?(currentBtnName?==?“btnJiaMi“)
????????????{
????????????????alreadyDone?=?“【已加密】“;
????????????}
????????????else
????????????{
????????????????alreadyDone?=?“【已解密】“;
????????????}
???????
????????????if?(txtFilePath.Text.Trim().Length?>?0)//加密解密文件
????????????{
????????????????srcPath?=?txtFilePath.Text.Trim();
????????????????
????????????????string?fileName?=?Path.GetFileName(srcPath);
????????????????fileName?=?GetName(fileName);
????????????????EncryptDEcrypt(srcPath?Path.Combine(Path.GetDirectoryName(srcPath)?alreadyDone?+?fileName));
????????????}
????????????else?if?(txtFloderPath.Text.Trim().Length?>?0)//加密解密文件夾
????????????{
????????????????srcPath?=?txtFloderPath.Text.Trim();
????????????????string?folderPath?=?Path.Combine(Directory.GetParent(srcPath).ToString()
????????????????????alreadyDone?+?GetName(Path.GetFileName(srcPath)));
????????????????if?(!Directory.Exists(folderPath))
????????????????{
????????????????????Directory.CreateDirectory(folderPath);
????????????????}
????????????????//先為當前目錄下文件加密
????????????????string[]?childFiles?=?Directory.GetFiles(srcPath);
????????????????foreach?(string?childfile?in?childFiles)
????????????????{
????????????????????EncryptDEcrypt(Path.GetFullPath(childfile)?Path.Combine(folderPath?Path.GetFileName(childfile)));
????????????????}
????????????????//遍歷目錄下所有文件
????????????????TraverseAllFile(srcPath?folderPath);
????????????}
????????????else
????????????{
????????????????srcPath?=?null;
????????????}
????????????if?(isErr?==?false)
????????????{
????????????????if?(btn.Name?==?“btnJiaMi“)
????????????????{
????????????????????MessageBox.Show(“加密完成“);
????????????????????txtFilePath.Text?=?““;
????????????????????txtFloderPath.Text?=?““;
????????????????????btnJieMi.Enabled?=?true;
????????????????????btnJiaMi.Enabled?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3865??2014-08-09?19:35??c#加密文件夾及文件\2014年8月4日IO流\2014年8月4日IO流.csproj
?????文件?????115712??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\bin\Release\2014年8月4日IO流.exe
?????文件??????28160??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\bin\Release\2014年8月4日IO流.pdb
?????文件??????11600??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\bin\Release\2014年8月4日IO流.vshost.exe
?????文件????????490??2009-08-31?00:40??c#加密文件夾及文件\2014年8月4日IO流\bin\Release\2014年8月4日IO流.vshost.exe.manifest
?????文件???????7063??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\Form1.cs
?????文件???????6831??2014-08-09?19:35??c#加密文件夾及文件\2014年8月4日IO流\Form1.Designer.cs
?????文件??????83015??2014-08-09?19:35??c#加密文件夾及文件\2014年8月4日IO流\Form1.resx
?????文件????????788??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\2014年8月4日IO流.csproj.FileListAbsolute.txt
?????文件????????975??2014-08-09?19:35??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\2014年8月4日IO流.csproj.GenerateResource.Cache
?????文件???????9080??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\2014年8月4日IO流.csprojResolveAssemblyReference.cache
?????文件?????115712??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\2014年8月4日IO流.exe
?????文件??????28160??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\2014年8月4日IO流.pdb
?????文件???????5359??2014-08-09?19:45??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\DesignTimeResolveAssemblyReferences.cache
?????文件???????6312??2014-08-11?17:54??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????51828??2014-08-09?19:35??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\_2014年8月4日IO流.Form1.resources
?????文件????????180??2014-08-09?19:35??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\_2014年8月4日IO流.Properties.Resources.resources
?????文件????????502??2014-08-09?19:35??c#加密文件夾及文件\2014年8月4日IO流\Program.cs
?????文件???????1392??2014-08-04?18:01??c#加密文件夾及文件\2014年8月4日IO流\Properties\AssemblyInfo.cs
?????文件???????2894??2014-08-04?18:01??c#加密文件夾及文件\2014年8月4日IO流\Properties\Resources.Designer.cs
?????文件???????5612??2014-08-04?18:01??c#加密文件夾及文件\2014年8月4日IO流\Properties\Resources.resx
?????文件???????1108??2014-08-04?18:01??c#加密文件夾及文件\2014年8月4日IO流\Properties\Settings.Designer.cs
?????文件????????249??2014-08-04?18:01??c#加密文件夾及文件\2014年8月4日IO流\Properties\Settings.settings
?????文件??????51262??2014-08-05?14:51??c#加密文件夾及文件\2014年8月4日IO流\文件名.ico
?????文件????????902??2014-08-04?18:01??c#加密文件夾及文件\2014年8月4日IO流.sln
????..A..H.?????27648??2014-08-11?17:55??c#加密文件夾及文件\2014年8月4日IO流.suo
?????目錄??????????0??2014-08-09?19:45??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Debug\TempPE
?????目錄??????????0??2014-08-09?19:28??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release\TempPE
?????目錄??????????0??2014-08-11?17:58??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Debug
?????目錄??????????0??2014-08-11?17:58??c#加密文件夾及文件\2014年8月4日IO流\obj\x86\Release
............此處省略11個文件信息
- 上一篇:c# panel的拖動和縮放
- 下一篇:c# sql數據庫操作類 增刪改查
評論
共有 條評論