|
发表于 2018-11-13 13:02:11
|
显示全部楼层
|阅读模式
云南省文山壮族苗族自治州
namespace 加密软件1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog对象 = new OpenFileDialog();
if (openFileDialog对象.ShowDialog()==DialogResult.OK)
{
txb1.Text= openFileDialog对象.FileName; //文件路径
}
}
private void btn2_Click(object sender, EventArgs e)
{
if (txb1.Text == "")
{
MessageBox.Show("请选择要加密的文件");
}
else
{
try
{
string strPath = txb1.Text;
int intlent = strPath.LastIndexOf("\\") + 1;
int intlong = strPath.Length;
string strName = strPath.Substring(intlent, intlong - intlent);
int intTxt = strName.LastIndexOf(".");
int intTxtleng = strName.Length;
string strTxt = strName.Substring(intTxt,intTxtleng-intTxt);
strName = strName.Substring(0, intTxt);//加密后的文件名及路径
// string strOutName = strPath.Substring(0, strPath.LastIndexOf("\\") + 1) + strName + "Out" + strTxt;//密钥
label1.Text = strName;
byte[] key = { 24, 55, 102, 24, 98, 26, 67, 29, 84, 19, 37, 118, 104, 85, 121, 27, 93, 86, 24, 55, 102, 24, 98, 26, 67, 29, 9, 2, 49, 69, 73, 92 };
byte[] IV = { 22, 56, 82, 77, 84, 31, 74, 24, 55, 102, 24, 98, 26, 67, 29, 99 };
RijndaelManaged myRijndael = new RijndaelManaged();
FileStream fsout = File.Open(strName, FileMode.Open, FileAccess.Write);
FileStream fsIn = File.Open(strPath, FileMode.Open, FileAccess.Read);
CryptoStream csDecrypt = new CryptoStream(fsout, myRijndael.CreateEncryptor(key, IV), CryptoStreamMode.Write);
BinaryReader br = new BinaryReader(fsIn);
csDecrypt.Write(br.ReadBytes((int)fsIn.Length), 0,(int)fsIn.Length);
csDecrypt.FlushFinalBlock();
csDecrypt.Close();
fsIn.Close();
fsout.Close();
if (MessageBox.Show("加密成功!加密成功后的文件名称及路径为:\n" + strName + ",是否删除源文件", "信息提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
File.Delete(strPath);
txb1.Text = "";
}
else
{
txb1.Text = "";
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
}
}
}
|
-
|