AES 文档加密器
很多时候要用到AES对文件加密,这里自己通过C#写了一个界面版的软件加密器,针对txt,word,和图片都有效。软件界面如图
核心代码如下:
namespace AESV
{public partial class 文档加密器 : Form{public 文档加密器(){InitializeComponent();}// 有密码的AES加密 public static byte[] Encrypt(byte[] toEncrypt, byte[] key){RijndaelManaged rDel = new RijndaelManaged();rDel.Key = key;rDel.Mode = CipherMode.ECB;rDel.Padding = PaddingMode.PKCS7;ICryptoTransform cTransform = rDel.CreateEncryptor();byte[] resultArray = cTransform.TransformFinalBlock(toEncrypt, 0, toEncrypt.Length);return resultArray;}// AES解密public static byte[] Decrypt(byte[] toDecrypt, byte[] key){RijndaelManaged rDel = new RijndaelManaged();rDel.Key = key;rDel.Mode = CipherMode.ECB;rDel.Padding = PaddingMode.None;ICryptoTransform cTransform = rDel.CreateDecryptor();byte[] resultArray = cTransform.TransformFinalBlock(toDecrypt, 0, toDecrypt.Length);return resultArray;}//加密的具体实现,有打开对话框和另存为对话框private void button1_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog1 = new SaveFileDialog();saveFileDialog1.FileName = "默认文件名";saveFileDialog1.Filter = "默认文件名" + " 文件|*.txt";if (saveFileDialog1.ShowDialog() != DialogResult.OK)return;if (saveFileDialog1.FileName == null || saveFileDialog1.FileName.Length <= 0){MessageBox.Show("文件名不能为空");return;}const int chunkSize = 12800;//每次读取文件,只读取100Mbyte[] byteContent = new byte[chunkSize];OpenFileDialog openFileDialog1 = new OpenFileDialog();string key = textBox1.Text;MD5 md5Hasher = MD5.Create();byte[] cKey = md5Hasher.ComputeHash(Encoding.Default.GetBytes(key));if (openFileDialog1.ShowDialog() == DialogResult.OK){if (File.Exists(openFileDialog1.FileName)){FileStream files = new FileStream(openFileDialog1.FileName, FileMode.Open);int lengthToRead = (int)files.Length;int lengthleft = lengthToRead;int lengthadd = 0;int round = (int)Math.Ceiling ((double)lengthToRead / (double)chunkSize);DateTime dt1 = DateTime.Now;FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create); if (lengthToRead > 0&lengthleft>0)//加密的时间{for (int i = 0; i <round; i++){if (lengthleft < chunkSize&lengthleft>0){byte[] byteShort = new byte[lengthleft];files.Read(byteShort, 0, lengthleft);byte[] enByte = Encrypt(byteShort, cKey);fs.Seek(lengthadd,SeekOrigin.Begin);fs.Write(enByte, 0, enByte.Length);}else{files.Read(byteContent, 0, chunkSize);byte[] enByte = Encrypt(byteContent, cKey);fs.Seek(lengthadd, SeekOrigin.Begin);fs.Write(enByte, 0, byteContent.Length);//write(byte,position,num)从第position个位置选取num个数放入程序内存中。}lengthadd += chunkSize;lengthleft -= chunkSize;/* int j = 0;j++;MessageBox.Show("运行的次数为:" + j);*/}}fs.Close();files.Close();DateTime dt2 = DateTime.Now;TimeSpan dt = dt2.Subtract(dt1);string dtd = dt.ToString();MessageBox.Show("加密的时间为:" + dtd);}}}private void button2_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog2 = new SaveFileDialog();saveFileDialog2.FileName = "默认文件名";saveFileDialog2.Filter = "默认文件名" + " 文件|*.txt";if (saveFileDialog2.ShowDialog() != DialogResult.OK)return;if (saveFileDialog2.FileName == null || saveFileDialog2.FileName.Length <= 0){MessageBox.Show("文件名不能为空");return;}const int chunkSize = 12800;//每次读取文件,只读取100Kbyte[] byteContent = new byte[chunkSize];OpenFileDialog openFileDialog2 = new OpenFileDialog();string key = textBox1.Text;MD5 md5Hasher = MD5.Create();byte[] cKey = md5Hasher.ComputeHash(Encoding.Default.GetBytes(key));if (openFileDialog2.ShowDialog() == DialogResult.OK){if (File.Exists(openFileDialog2.FileName)){FileStream files = new FileStream(openFileDialog2.FileName, FileMode.OpenOrCreate); int lengthToRead = (int)files.Length;int lengthleft = lengthToRead;int lengthadd = 0;int round = (int)Math.Ceiling((double)lengthToRead / (double)chunkSize);//解密的时间FileStream fs = new FileStream(saveFileDialog2.FileName, FileMode.Create);DateTime dt1 = DateTime.Now;if (lengthToRead > 0 & lengthleft > 0)//加密的时间{for (int i = 0; i < round; i++){if (lengthleft < chunkSize & lengthleft > 0){byte[] byteShort = new byte[lengthleft];files.Read(byteShort, 0, lengthleft);byte[] enByte = Decrypt(byteShort, cKey);fs.Seek(lengthadd, SeekOrigin.Begin);if (i == round -1)fs.Write(enByte, 0, enByte.Length - 16 + lengthToRead % 16);elsefs.Write(enByte, 0, enByte.Length);//write(byte,position,num)从第position个位置选取num个数放入程序内存中。lengthadd += chunkSize;}else{files.Read(byteContent, 0, chunkSize);byte[] enByte =Decrypt(byteContent, cKey);fs.Seek(lengthadd , SeekOrigin.Begin);fs.Write(enByte, 0, byteContent.Length);//write(byte,position,num)从第position个位置选取num个数放入程序内存中。lengthadd += chunkSize;}lengthleft -= chunkSize;}}fs.Close();files.Close();//此处使用AES-128-ECB加密模式,key需要为16位。DateTime dt2 = DateTime.Now;TimeSpan dt = dt2.Subtract(dt1);string dtd = dt.ToString();MessageBox.Show("解密的时间为:" + dtd);}}}public object Flase { get; set; }private void textBox1_TextChanged(object sender, EventArgs e){TextBox TextBox1 = sender as TextBox;TextBox1.PasswordChar = '*';TextBox1.MaxLength = 16;textBox1.TextAlign = HorizontalAlignment.Center;}private void label1_Click(object sender, EventArgs e){}}//类结束;
}//命名空间结束;
AES 文档加密器相关推荐
- Word文档加密器(最新版V6.0)
Word文档加密器(最新版V6.0) Word文档加密保护唯一选择,一机一码分发 加密word文档,支持*.doc;*.rtf;*.docx;*.docm; 保护word文档分发,防止编辑.防止复制. ...
- 自己开发的加密工具---照片文档加密器
自己开发的工具 软件名:照片文档加密器 软件大小:16KB 软件语言:简体中文 软件性质:免费软件 联系人:ys_ck#163.com 下载地址:http://kfysckgraph.sinaapp. ...
- python实现AES加解密文档里英文字符串
python实现AES加解密文档里英文文章 AES加解密文档里英文字符串 英文文档中也包含了空格与回车符 加密过程 首先读取文件中的内容 将文档中的内容读取,然后将其赋予你申请的变量 在我的实验中我的 ...
- aes c语言 逆列混合函数,c语言aes列混合和逆列混合的实现(3页)-原创力文档
#include #include //函数声明 unsigned char xtime (unsigned char input); void mixcolum(unsigned char inpu ...
- html文档主体的根标签,2 HTML简介标签嵌套和并列关系文档声明
HTML:Hyper Text Markup Language 超文本标签语言(hyper:精力旺盛的 markup:标记 n noun) HTML不是编程语言,而是一种标记语言(就是一套标记标签) ...
- 又拍云 php5月18号那,又拍云文档中心
移动流量 平台概述¶ 又拍云手机流量营销平台,整合移动.电信.联通三大运营商流量资源,将强大的流量营销服务,通过接口等形式提供给商家合作伙伴,帮助商家开展品牌宣传.APP/游戏/微信公众号/网站的拉新 ...
- {过时·留存}MS Office文档
涉及资料均来源于公开网络 仅作留存,谬误难免 算是一些过时笔记吧,没找到文字,只有PDF了,就酱吧. 学习需要,曾对部分版本的Office文档加密算法进行了验证,主要是2007.2003.2000及兼 ...
- 给文档加密,你懂多少?
一直以来有个写日记的习惯,但自从拥有了自己的电脑开始在电脑上练手.说句实在的,我还是比较习惯将日记看作自己的隐私,不用密码本,那么我就该在文档中实现加密.但我写日记没有在日记文档中,反而在word文档 ...
- 微软office在线文档_如何使用Microsoft Office密码保护文档和PDF
微软office在线文档 Microsoft Office lets you encrypt your Office documents and PDF files, allowing no one ...
最新文章
- rsync同步和备份文件到本地
- 【Network Security!】认识进程与端口
- Linux 2.6内核配置说明(File systems文件系统)
- JZOJ 5637. 【NOI2018模拟4.8】一双木棋
- java输出hello word,教你如何配置java环境输出"hello word!"?
- 蓝桥杯2015 C语言大学B组 C/C++
- Android 使用ViewPager实现画廊Gallery效果
- 【转】mutation接收单个参数和多个参数
- sdk的安装与环境配置
- 速读-对抗攻击的弹性异构DNN加速器体系结构
- 【C语言】实现 4阶(经典)龙格-库塔法 求解二阶微分方程
- Python的pyhanlp库使用(自然语言识别、姓名)
- 学生信息管理系统可行性研究报告
- windows c语言新建dos,dos命令怎么用_DOS下创建文件、文件夹
- python Django 快捷键
- java poi导出PPT格式
- 2019年中兴秋招在线笔试题目
- 【毕业设计】基于单片机的门禁系统 - 嵌入式 物联网
- 游戏推广的引流软件有用吗
- Pre-Trained_Models_Past_Present_and_Future
热门文章
- 明星签名长啥样?古天乐王源字体笑翻 大张伟出乎意料
- 信用评分分卡简介introduction of credit score card
- 时尚前卫 气质优雅——现代轻奢
- AdaBoost算法详解
- 中国地质大学(武汉)本科毕业论文答辩和论文选题PPT模板
- linux实验下载,linux实验linux实验.doc
- 字符串大小写转换html,javascript 字符串大小写转换的方法
- html邮件 正文图片不显示,如何在电子邮件正文中显示图像?
- (2020.1.13已解决)ImportError: cannot import name 'StringIO'
- 将Hexo搭建到自己的服务器上