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压缩加密的更多相关文章

  1. 在 Mac OS X 中建立加密的 Zip 压缩 -- 让机密资料加上密码

    在 Mac OS X 中要压缩档案的話,基本上就用滑鼠点右鍵选「压缩...」就可以制作 Zip 格式的压缩档,很方便.但如果是机密的资料要透过 Email 等管道传送时,常常会需要建立加密的 Zip ...

  2. 记录新项目中遇到的技术及自己忘记的技术点【DES加密解密,MD5加密,字符串压缩、解压,字符串截取等操作】

    一.DES加密.解密 #region DES加密解密 /// <summary> /// 进行DES加密 /// </summary> /// <param name=& ...

  3. DirectX 安装报错: 不能信任一个安装所需的压缩文件,请检查加密服务是否启用并且cabinet文件证书是否有效

    DirectX 安装报错 不能信任一个安装所需的压缩文件,请检查加密服务是否启用并且cabinet文件证书是否有效 是直播软件open broadcaster software,这个软件安装的时候提示 ...

  4. vb.net加密解密方法

    1.vb.net加密解密方法 Private Function getLicenseDate() As String Dim b() As Byte Dim path As String = Serv ...

  5. Android 中 非对称(RSA)加密和对称(AES)加密

    在非对称加密中使用的主要算法有:RSA.Elgamal.背包算法.Rabin.D-H.ECC(椭圆曲线加密算法)等. 优点: 非对称加密与对称加密相比,其安全性更好:对称加密的通信双方使用相同的秘钥, ...

  6. 【Java】:压缩成多个压缩卷

    Java自带的库不支持压缩成多个压缩卷,找到了一个开源库 zip4j ,发现更好用 so easy package com.jws.common.mail; import java.io.File; ...

  7. PHP、Java对称加密中的AES加密方法

    PHP AES加密 <?php ini_set('default_charset','utf-8'); class AES{ public $iv = null; public $key = n ...

  8. AES加密和Base64混合加密

    /// <summary> /// AES加密方法(AES加密和Base64混合加密) /// </summary> /// <param name="toEn ...

  9. php代码加密|PHP源码加密——实现方法

    Encipher - PHP代码加密 | PHP源码加密下载地址:https://github.com/uniqid/encipher 该加密程序是用PHP代码写的,加密后代码无需任何附加扩展,无需安 ...

随机推荐

  1. 【转】ffmpeg参数中文详细解释

    感谢“大神”的无私奉献:http://blog.csdn.net/leixiaohua1020/article/details/15811977 a) 通用选项 -L license-h 帮助-fro ...

  2. [YY]已知逆序列求原序列(二分,树状数组)

    在看组合数学,看到逆序列这个概念.于是YY了一道题:已知逆序列,求出原序列. 例子: 元素个数 n = 8 逆序列 a={5,3,4,0,2,1,1,0} 则有原序列 p={4,8,6,2,5,1,3 ...

  3. 【原创分享】python获取乌云最新提交的漏洞,邮件发送

    #!/usr/bin/env python # coding:utf-8 # @Date : 2016年4月21日 15:08:44 # @Author : sevck (sevck@jdsec.co ...

  4. ios uiview封装动画(摘录)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

  5. 历史命令history

    历史命令在用户注销之后会保存在用户家目录下的-/.bash_history中 history #查看系统中实时缓存的历史命令,与.bash_history中的内容并不完全相同 history -c # ...

  6. Codeforces Round #257 (Div. 2) A题

    A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. Python基础学习笔记(十)日期Calendar和时间Timer

    参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-date-time.html 3. http://www.liao ...

  8. hd1496---->这道题是水水的数论吗?

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1496 题意: Consider equations having the following form: ...

  9. iOS - UICollectionViewController

    前言 NS_CLASS_AVAILABLE_IOS(6_0) @interface UICollectionView : UIScrollView @available(iOS 6.0, *) pub ...

  10. 超实用压力测试工具-ab工具

    在学习ab工具之前,我们需了解几个关于压力测试的概念 吞吐率(Requests per second)概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求 ...