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. UVA 10564 十 Paths through the Hourglass

     Paths through the Hourglass Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & % ...

  2. iOS 关于使用xib创建cell的两种初始化方式

    [转]http://my.oschina.net/CgShare/blog/337406 方法一: 第一步: [self.collectionView registerNib:[UINib nibWi ...

  3. about_Execution_Policies

    https://technet.microsoft.com/en-us/library/hh847748.aspx?f=255&MSPPError=-2147217396 在powershel ...

  4. Creating Excel File in Oracle Forms

    Below is the example to create an excel file in Oracle Forms.Pass the Sql query string to the below ...

  5. VSFTP基线安全

    在企业级的应用中,越来越多的企业应用开源的vsftpd软件来搭建自己的文件共享服务,优点是速度快且节省开支.然而,企业用户行为难以预料,配置稍有不当则会使该服务成为一个安全风险点,导致带宽恶意占用.用 ...

  6. 构建一个简单的Maven项目

    这里用Maven Archetype插件从空白开始创建简单的项目. 熟悉Maven 项目和Maven的核心概念. 关键词:构建生命周期(build lifecycle), Maven仓库(reposi ...

  7. [Effective Java]第二章 创建和销毁对象

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

  8. 图--DFS求连通块

                                  The GeoSurvComp geologic survey company is responsible for detecting u ...

  9. RedHat安装DB2详细步骤(附卸载、备份恢复步骤)

    1.创建用户组和用户 说明: 步骤1 以root用户登录需要安装DB2的服务器. 步骤2 创建用户组和用户. # su -root # groupdel db2grp # groupdel db2fg ...

  10. Android_使用 OpenVPN

    1. 需要 root http://www.doc88.com/p-847633362717.html http://bbs.gfan.com/android-3679297-1-1.html 需要 ...