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. 【leetcode❤python】 219. Contains Duplicate II

    #-*- coding: UTF-8 -*-#遍历所有元素,将元素值当做键.元素下标当做值#存放在一个字典中.遍历的时候,#如果发现重复元素,则比较其下标的差值是否小于k,#如果小于则可直接返回Tru ...

  2. NSIntger CGFloat NSNumber

    NSIntger  CGFloat  NSNumber 1.NSIntger  (long) %ld NSInteger a=; NSLog(@"----------%ld",(l ...

  3. CCNA training notes

    5/29: vlan:virtual lan, 通过PVID来将物理上连通的host/PC划分到不同的局域网. switch的每个port有access与trunk两种mode,trunk模式的por ...

  4. shell 随机从文件中抽取若干行

    shuf -n5 main.txt sort -R main.txt | head -5 awk -vN=5 -vC="`wc -l file`" 'BEGIN{srand();w ...

  5. Spring与其他Web框架集成

    Spring与多种流行Web应用框架(Struts.JSF和DWR)集成的方法. Spring强大的IoC容器和企业支持特性使其十分适于实现Java EE应用的服务和持续层. 对于表现层,可以在许多不 ...

  6. Servlet异常及其生命周期

    Servlet 异常 在javax.servlet包中定义了两个异常类 ServletException类 ServletException类定义了一个通用的异常,可以被init().service( ...

  7. Native SQL

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  8. iOS案例:读取指定目录下的文件列表

    // // main.m // 读取指定目录下的文件列表 // // Created by Apple on 15/11/24. // Copyright © 2015年 Apple. All rig ...

  9. DB2常识

    1.DB2组件 appendixa. db2 database product and packaging informatin一节AESE: 高级企业服务器版(Advanced enterprise ...

  10. 在beforeAction里redirect无效,Yii2.0.8

    我是在官方GitHub上得到回答,试了一下,确实解决问题了.之前的问题描述: 之前是2.0.3,然后用composer直接升级到2.0.8,就不正常了,以为是我代码的问题,于是再次尝试 用compos ...