C#压缩加密和vb压缩加密
string[] FileProperties = new string[2];
FileProperties[0] = "C:\\a\\";//待压缩文件目录
FileProperties[1] = "C:\\zip\\a.zip"; //压缩后的目标文件
zipclass Zc = new zipclass();
Zc.ZipFileMain(FileProperties,"123");
压缩文件夹 加密
public void ZipFileMain(string[] args, string password)
{
string[] filenames = Directory.GetFiles(args[0]);
ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
s.SetLevel(6); // 0 - store only to 9 - means best compression
s.Password = password;
foreach (string file in filenames)
{
//打开压缩文件
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
Array arr = file.Split('\\');
string le = arr.GetValue(arr.Length - 1).ToString();
ZipEntry entry = new ZipEntry(le);
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
}
}
通过密码解压
public void UnZip(string[] args, string password)
{
string directoryName = Path.GetDirectoryName(args[1]);
using (FileStream fileStreamIn = new FileStream(args[0], FileMode.Open, FileAccess.Read))
{
using (ZipInputStream zipInStream = new ZipInputStream(fileStreamIn))
{
zipInStream.Password = password;
ZipEntry entry = zipInStream.GetNextEntry();
do
{
using (FileStream fileStreamOut = new FileStream(directoryName + @"\" + entry.Name, FileMode.Create, FileAccess.Write))
{ int size = 2048;
byte[] buffer = new byte[2048];
do
{
size = zipInStream.Read(buffer, 0, buffer.Length);
fileStreamOut.Write(buffer, 0, size);
} while (size > 0);
}
} while ((entry = zipInStream.GetNextEntry()) != null);
}
}
} 压缩某个文件
public void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize)
{
if (!System.IO.File.Exists(FileToZip))
{
throw new System.IO.FileNotFoundException("The specified file " + FileToZip + " could not be found. Zipping aborderd");
} System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
ZipEntry ZipEntry = new ZipEntry("ZippedFile");
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(CompressionLevel);
byte[] buffer = new byte[BlockSize];
System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, size);
try
{
while (size < StreamToZip.Length)
{
int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, sizeRead);
size += sizeRead;
}
}
catch (System.Exception ex)
{
throw ex;
}
ZipStream.Finish();
ZipStream.Close();
StreamToZip.Close();
}
通过工具c#转vb得出基本代码http://converter.telerik.com/
Imports ICSharpCode.SharpZipLib.Zip
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim FileProperties As String() = New String(1) {}
FileProperties(0) = "C:\a\"
'待压缩文件目录
FileProperties(1) = "C:\zip\a.zip"
'压缩后的目标文件
ZipFileMain(FileProperties, "123")
End Sub
Private Function ZipFileMain(args As String(), password As String) As String
Dim filenames As String() = Directory.GetFiles(args(0))
Dim myTank As ZipOutputStream
myTank = New ZipOutputStream(File.Create(args(1)))
myTank.SetLevel(6)
myTank.Password = password
For Each file__1 As String In filenames
'打开压缩文件
Dim fs As FileStream = File.OpenRead(file__1)
Dim buffer As Byte() = New Byte(fs.Length - 1) {}
fs.Read(buffer, 0, buffer.Length)
Dim arr As Array = file__1.Split("\"c)
Dim le As String = arr.GetValue(arr.Length - 1).ToString()
Dim entry As New ZipEntry(le)
entry.DateTime = DateTime.Now
entry.Size = fs.Length
fs.Close()
myTank.PutNextEntry(entry)
myTank.Write(buffer, 0, buffer.Length)
Next
myTank.Finish()
myTank.Close()
Return password
End Function
End Class
C#压缩加密和vb压缩加密的更多相关文章
- 在 Mac OS X 中建立加密的 Zip 压缩 -- 让机密资料加上密码
在 Mac OS X 中要压缩档案的話,基本上就用滑鼠点右鍵选「压缩...」就可以制作 Zip 格式的压缩档,很方便.但如果是机密的资料要透过 Email 等管道传送时,常常会需要建立加密的 Zip ...
- 记录新项目中遇到的技术及自己忘记的技术点【DES加密解密,MD5加密,字符串压缩、解压,字符串截取等操作】
一.DES加密.解密 #region DES加密解密 /// <summary> /// 进行DES加密 /// </summary> /// <param name=& ...
- DirectX 安装报错: 不能信任一个安装所需的压缩文件,请检查加密服务是否启用并且cabinet文件证书是否有效
DirectX 安装报错 不能信任一个安装所需的压缩文件,请检查加密服务是否启用并且cabinet文件证书是否有效 是直播软件open broadcaster software,这个软件安装的时候提示 ...
- vb.net加密解密方法
1.vb.net加密解密方法 Private Function getLicenseDate() As String Dim b() As Byte Dim path As String = Serv ...
- Android 中 非对称(RSA)加密和对称(AES)加密
在非对称加密中使用的主要算法有:RSA.Elgamal.背包算法.Rabin.D-H.ECC(椭圆曲线加密算法)等. 优点: 非对称加密与对称加密相比,其安全性更好:对称加密的通信双方使用相同的秘钥, ...
- 【Java】:压缩成多个压缩卷
Java自带的库不支持压缩成多个压缩卷,找到了一个开源库 zip4j ,发现更好用 so easy package com.jws.common.mail; import java.io.File; ...
- PHP、Java对称加密中的AES加密方法
PHP AES加密 <?php ini_set('default_charset','utf-8'); class AES{ public $iv = null; public $key = n ...
- AES加密和Base64混合加密
/// <summary> /// AES加密方法(AES加密和Base64混合加密) /// </summary> /// <param name="toEn ...
- php代码加密|PHP源码加密——实现方法
Encipher - PHP代码加密 | PHP源码加密下载地址:https://github.com/uniqid/encipher 该加密程序是用PHP代码写的,加密后代码无需任何附加扩展,无需安 ...
随机推荐
- 我的android学习经历20
WebView的使用 WebView既可以和Intent一样实现界面跳转一样,让系统浏览器打开页面,也可以在应用程序中打开页面 注意用WebView时,需要注册网络服务 代码如下: package c ...
- ZOJ 1015 Fishing Net(判断弦图)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=15 题意:给定一个图.判断是不是弦图? 思路:(1)神马是弦图?对于一 ...
- C++实现二叉树,运用模板,界面友好,操作方便 运行流畅
//.h文件 #ifndef TREE_H #define TREE_H #include<iostream> #include<iomanip> using namespac ...
- CodeForces 152C Pocket Book
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Prac ...
- Python串口编程
python的串口网上有很多例子,这里了只是把认为好的整理到一起. 首先,应该安装serial模块,还能开始后续的操作.我用的python2.6,serial模块可以在这里下载安装serial模块下载 ...
- C# WPF – 利用“Attached Property” 把 RoutedEvent 接上 ICommand
本文说明怎样把 DoubleClick 连接至 ICommand.方法很多.推荐使用 Attach Property 方式,因为它能把任何 RoutedEvent 接上任何 ICommand. 之前写 ...
- 用jq移除某一个特定样式
用JQ移除样式中的某条单独的样式,实际移除不了的,只能将其赋值为空$(function(){ $(".tableStyle").css("background-color ...
- Hibernate之N+1问题
什么是hibernate的N+1问题?先了解这样一个描述: 多个学生可以对应一个老师,所以student(n)---teacher(1).Stu类中有一个属性teacher.在hibernate配置文 ...
- Linux命令工具基础02 文件及目录管理
文件及目录管理 文件管理不外乎文件或目录的创建.删除.查询.移动,有mkdir/rm/mv 文件查询是重点,用find来进行查询:find的参数丰富,也非常强大: 查看文件内容是个大的话题,文本的处理 ...
- 学习python得到方向与主体
Python的主体内容大致可以分为以下几个部分: 面向过程.包括基本的表达式,if语句,循环,函数等.如果你有任何一个语言的基础,特别是C语言的基础,这一部分就是分分钟了解下Python规定的事.如果 ...