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

推荐订阅源

V
Vulnerabilities – Threatpost
V
V2EX
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
Y
Y Combinator Blog
C
Check Point Blog
爱范儿
爱范儿
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
美团技术团队
雷峰网
雷峰网
IT之家
IT之家
WordPress大学
WordPress大学
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
N
News and Events Feed by Topic
罗磊的独立博客
S
SegmentFault 最新的问题
S
Security Affairs
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Google DeepMind News
Google DeepMind News
B
Blog
O
OpenAI News
C
Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
Hacker News: Ask HN
Hacker News: Ask HN
博客园_首页
人人都是产品经理
人人都是产品经理
C
Cybersecurity and Infrastructure Security Agency CISA
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Help Net Security
Help Net Security
月光博客
月光博客
J
Java Code Geeks
L
LangChain Blog
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Apple Machine Learning Research
Apple Machine Learning Research
T
The Exploit Database - CXSecurity.com
N
News and Events Feed by Topic
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 邢帅杰

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);