2023年12月18日发(作者:)
教你如何做个简单的文件夹加密的应用程序,很详细哦!包括界面设计和代码。首先是设计主窗口。代码如下:
xmlns="/winfx/2006/xaml/presentation" xmlns:x="/winfx/2006/xaml" ResizeMode="NoResize" Title="MainWindow" Height="255" Width="481">
效果如下:
然后是背后的执行代码:
using System;
using c;
using ;
using ;
using s;
using ls;
using ;
using nts;
using ;
using ;
using g;
using tion;
using ;
using ;
using ;
namespace 文件夹加密
{
///
/// 的交互逻辑
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DirectoryInfo
bool result;
result = (@"D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}");
if (result == false)
{
();
}
//如果没有D:文件夹加密账号密码.txt则创建
if (!(@"D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}))
{
FileStream
e();
}
BinaryReader datain = new BinaryReader(new FileStream("D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}", ));
if (on==)
{
e();
initialization_password obj = new initialization_password();
();
();
}
}
fs = new FileStream("D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}", );
directory = new DirectoryInfo(@"D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}");
private void changpassword_Click(object sender, RoutedEventArgs e)
{
chang_password obj = new chang_password();
();
();
}
private void encrypt_Click(object sender, RoutedEventArgs e)
{
BinaryReader datain = new BinaryReader(new FileStream("D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}账号密码", ));
string str=ring();
if (rd == str)
{
BrowserDialog
BrowserDialog();
string path;
if (alog() == )
{
path= edPath;
}
DirectoryInfo dir = new DirectoryInfo(edPath);
if (dexOf(".{") == -1)
{
(edPath
".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}");
("加密成功");
}
else
{
("已经加密了!?");
}
e();
}
else
{
("密码错误!");
e();
}
}
private void deciphering_Click(object sender, RoutedEventArgs e)
{
BinaryReader datain = new BinaryReader(new FileStream("D:文件夹加+
folder = new
密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}账号密码", ));
string str = ring();
if (rd == str)
{
BrowserDialog
BrowserDialog();
string path;
if (alog() == )
{
path = edPath;
}
DirectoryInfo dir = new DirectoryInfo(edPath);
string shiyan = ;
int len =;
int len1 = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}".Length;
int len2 = ;
int distance=len2-len1;
if (distance>0)
{
string path1 = ing(0, len - len1);
(path1);
("文件夹已经解密了!");
}
else
{
("文件夹没有被加密!");
}
e();
}
else
{
("密码错误!");
e();
}
}
}
}
folder = new
然后是初始化密码的界面设计和代码:
xmlns="/winfx/2006/xaml/presentation" xmlns:x="/winfx/2006/xaml" Title="initialization_password" Height="169" Width="419">
效果如下:
背后的代码如下:
using System;
using c;
using ;
using ;
using s;
using ls;
using ;
using nts;
using ;
using ;
using g;
using ;
using ;
using ing;
namespace 文件夹加密
{
///
/// initialization_ 的交互逻辑
///
public partial class initialization_password : Window
{
public initialization_password()
{
InitializeComponent();
}
private void ok_Click(object sender, RoutedEventArgs e)
{
if (password_rd == password_rd)
{
BinaryWriter dataout = new BinaryWriter(new FileStream("D:文?件t夹D加ó密ü.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}账号密码", ));
(password_rd);
DirectoryInfo dir = new DirectoryInfo("D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}账号密码");
e();//这里很重要注意要放资源
MainWindow obj = new MainWindow();
("密码设置成功!");
();
();
}
}
}
}
最后是修改密码的界面设计和执行代码:
xmlns="/winfx/2006/xaml/presentation" xmlns:x="/winfx/2006/xaml" Title="chang_password" Height="300" Width="498"> Margin="40,46,0,0" Name="label1" VerticalAlignment="Top" Width="102" /> Margin="40,102,0,0" Name="label2" VerticalAlignment="Top" Width="102" /> Margin="198,46,0,0" VerticalAlignment="Top" Width="167" /> Margin="198,102,0,0" VerticalAlignment="Top" Width="167" /> Margin="198,152,0,0" VerticalAlignment="Top" Width="167" /> HorizontalAlignment="Left" Margin="366,204,0,0" VerticalAlignment="Top" Width="86" Click="ok_button_Click" /> Margin="40,152,0,0" Name="label3" VerticalAlignment="Top" Width="102" />
效果如下:
背后代码如下:
using System;
using c;
using ;
using ;
using s;
using ls;
using ;
using nts;
using ;
using ;
using g;
using ;
using ;
using ing;
namespace 文件夹加密
{
///
/// chang_ 的交互逻辑
///
public partial class chang_password : Window
{
public chang_password()
{
InitializeComponent();
}
private void ok_button_Click(object sender, RoutedEventArgs e)
{
BinaryReader datain = new BinaryReader(new FileStream("D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}账号密码", ));
string str=ring();
if (str != password_rd)
{
("原始密码错误!");
e();
}
else
if (password_rd ==""||password_new_rd=="")
{
("未填完内容!");
e();
}
else
if (password_rd != password_new_rd)
{
("新密码和确定密码不一致!");
e();
}
else
{
e();
BinaryWriter dataout = new BinaryWriter(new FileStream("D:文件夹加密.{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}账号密码", ));
(password_new_rd);
("密码修改成功!");
e();
(1000);
MainWindow obj = new MainWindow();
();
();
}
}
}
}
最后加密的文件夹效果如下,你可以把需要加密的东西放在这个文件夹中别人一般打不开的:
当然如果喜欢的话还可以到我的网盘去下载:/share/home?uk=2636013727


发布评论