des加密文件
来源:互联网 发布:淘宝女装店铺招牌图片 编辑:程序博客网 时间:2024/05/22 12:52
private void button1_Click(object sender, EventArgs e)
{
DES des = new DESCryptoServiceProvider();
EncryptData("1.txt", "2.txt", des.Key, des.IV);
DecryptData("2.txt", "3.txt", des.Key, des.IV);
}
private void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV)
{//加密文件
//Create the file streams to handle the input and output files.
FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
fout.SetLength(0);
//Create variables to help with read and write.
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
long rdlen = 0; //This is the total number of bytes written.
long totlen = fin.Length; //This is the total length of the input file.
int len; //This is the number of bytes to be written at a time.
DES des = new DESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
//Read from the input file, then encrypt and write to the output file.
while (rdlen < totlen)
{
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
}
encStream.Close();
fout.Close();
fin.Close();
}
//解密文件
private void DecryptData(String inName, String outName, byte[] desKey, byte[] desIV)
{
//Create the file streams to handle the input and output files.
FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
fout.SetLength(0);
//Create variables to help with read and write.
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
long rdlen = 0; //This is the total number of bytes written.
long totlen = fin.Length; //This is the total length of the input file.
int len; //This is the number of bytes to be written at a time.
DES des = new DESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fout, des.CreateDecryptor(desKey, desIV), CryptoStreamMode.Write);
//Read from the input file, then encrypt and write to the output file.
while (rdlen < totlen)
{
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
}
encStream.Close();
fout.Close();
fin.Close();
}
- des加密文件
- 文件DES加密解密
- des文件加密、解密
- DES加密文件
- DES加密解密文件
- des文件加密
- asp 的DES加密文件
- asp 的DES加密文件
- DES加密解密算法文件
- java DES加密解密文件
- java DES加密解密文件
- Java DES文件加密解密
- IOS-plist文件DES加密
- 3DES文件加密程序
- IOS-plist文件DES加密
- DES 文件加密, RSA 给密码加密
- 使用Des,MD5 加密.解密.字符串.文件
- 使用Des,MD5 加密.解密.字符串.文件
- 请问如何购买《中国电子地图2006》?
- 《世界·领主》开发日志[03]
- 闲逸小憩
- 如何制作单点地图? 有何功能?
- 我要地图桌面版下载
- des加密文件
- 电子地图2006下载
- Java程序员的十条戒律
- 英国签证信息中心
- Scott Mitchell 的ASP.NET 2.0数据教程之十五:在GridView的页脚中显示统计信息
- 從頭開始創建控件
- Eclipse 3.2 + lomboz + Tomcat 5.5 开发Struts 项目时遇到的问题
- 备忘链接
- 每月与英国签证官网聊?