惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
ThreatConnect
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
H
Help Net Security
T
Threat Research - Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
A
Arctic Wolf
G
Google Developers Blog
量子位
U
Unit 42
I
InfoQ
V
V2EX
F
Fox-IT International blog
P
Privacy & Cybersecurity Law Blog
V
Visual Studio Blog
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
C
CERT Recently Published Vulnerability Notes
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
T
Tailwind CSS Blog
SecWiki News
SecWiki News
Know Your Adversary
Know Your Adversary
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
The Hacker News
The Hacker News
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
月光博客
月光博客
Recent Commits to openclaw:main
Recent Commits to openclaw:main
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
C
Cisco Blogs
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
Recorded Future
Recorded Future
T
Tenable Blog
W
WeLiveSecurity
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
T
The Blog of Author Tim Ferriss
www.infosecurity-magazine.com
www.infosecurity-magazine.com
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
PCI Perspectives
PCI Perspectives

博客园 - 邢帅杰

CSRedisCore用法 Android 常用数据目录(内部 / 外部、缓存、文件) 的 获取方法对照表 安卓把assets中的文件copy到app目录中 oracle执行sql语句前清除缓存 安卓开发使用interface自定义回调函数 安装DockerDesktop并启用 oracle中decode用法 - 邢帅杰 vue使用import.meta编译报错,import.meta.env报:类型“ImportMeta”上不存在属性“env”。必须配置module。 oracle游标使用详解 oracle存储过程中声明一个行变量,接收游标中的行数据。variable_name table_name%ROWTYPE oracle NVL和NVL2 C#获取文件md5码 oracle查询存储过程和函数中是否包含某个字符串 Android清除WebView缓存 C#获取当前日期是星期几 切换项目git地址,项目迁移到新git地址 - 邢帅杰 C#线程同步、跨进程同步Mutex详解、C#只允许运行一个实例 Android Stack说明 安卓打开第三方app并传入参数 安卓如何唤醒深度睡眠的设备并执行任务 java两个日期相差秒数
.net core使用SharpZipLib压缩zip文件并设置密码
邢帅杰 · 2026-05-28 · via 博客园 - 邢帅杰

nuget安装SharpZipLib

/// <summary>
/// 压缩zip并设置密码
/// </summary>
/// <param name="sourceDir">要压缩的目录</param>
/// <param name="zipFile">压缩后zip存放地址</param>
/// <param name="password">密码</param>
public static void CreateZipPwd(string sourceDir, string zipFile, string password)
{
    if (File.Exists(zipFile)) File.Delete(zipFile);

    using (FileStream fs = new FileStream(zipFile, FileMode.Create))
    using (ZipOutputStream zipOut = new ZipOutputStream(fs))
    {
        zipOut.Password = password;
        zipOut.UseZip64 = UseZip64.On;
        zipOut.SetLevel(Deflater.DEFAULT_COMPRESSION);

        AddDirectoryToZip(zipOut, sourceDir, sourceDir);
    }
}
private static void AddDirectoryToZip(ZipOutputStream zipOut, string currentDir, string rootDir)
{
    foreach (string file in Directory.GetFiles(currentDir))
    {
        FileInfo fi = new FileInfo(file);
        string relPath = Path.GetRelativePath(rootDir, file).Replace("\\", "/");

        ZipEntry entry = new ZipEntry(relPath);
        entry.DateTime = fi.LastWriteTime;
        entry.Size = fi.Length;

        zipOut.PutNextEntry(entry);

        using (FileStream fs = fi.OpenRead())
            fs.CopyTo(zipOut);

        zipOut.CloseEntry();
    }

    foreach (string dir in Directory.GetDirectories(currentDir))
        AddDirectoryToZip(zipOut, dir, rootDir);
}

demo

 string sourceDir = "E:\\2026";
 string zipFile = "E:\\2026-01.zip";
 string password = "123456";
 CreateZipPwd(sourceDir, zipFile, password);