如何使用 C# 鎖定 Zip 存檔

Aspose.Zip for .NET 是一款功能強大的應用程序,它使開發人員能夠輕鬆鎖定 zip 存檔並為其文件添加額外的安全層。通過使用 Aspose.Zip 庫提供的 Lock 方法,開發人員可以毫不費力地為他們的 zip 存檔設置密碼。此功能可確保只有經過授權的個人才能訪問檔案內容,從而保護敏感數據免遭未經授權的訪問。支持各種壓縮格式,如 ZIP、GZIP、BZIP2、TAR、CPIO、LZIP、7Z、LZMA、XZ 和 Z,Aspose.Zip 為處理不同的存檔類型提供了全面的解決方案。直觀且用戶友好的 API 允許開發人員將密碼保護無縫集成到他們的 .NET 應用程序中,無論它們是基於 Web 還是 Zip 在線應用程序 在 Windows、Linux 或 macOS 上運行。通過使用 Aspose.Zip,開發人員可以增強其 zip 存檔的安全性並確保其文件的機密性。

使用文件壓縮和存檔 .NET API 管理 NuGet 包

Aspose.ZIP for .NET 是一個功能強大的類庫,專為.NET 開發人員設計,用於處理各種存檔處理任務。它支持 ZIP、GZIP、BZIP2、TAR、CPIO、LZIP、7Z、LZMA、XZ 和 Z 等多種格式,提供了廣泛的功能。開發人員可以利用此庫來加密和解密文件、創建自解壓存檔以及提取 RAR、CAB 和 WIM 格式。

API 用戶友好,簡單可靠.它使用託管 C# 實現,可以與任何 .NET 語言無縫集成,包括 C#、VB.NET 和 F#。無論您是在處理 ASP.NET Web 應用程序還是表單應用程序,無論是 Windows、Linux 還是 MacOS 操作系統,它都可以輕鬆集成。通過使用 Aspose.ZIP for .NET,開發人員獲得了一個通用的解決方案來處理其 .NET 應用程序中的存檔處理任務。


在 C# 中保護 Zip 存檔的步驟

Protecting archive using password with

Aspose.ZIP for .NET

APIs can be done with just few lines of code.

  • Create FileStream object with the output ZIP archive file path as parameter with mod FileMode.Create.
  • Open and read the source file into a FileStream object with mod FileMode.Open and FileAccess.Read.
  • Create Archive class object with ArchiveEntrySettings object as parameter.
  • Use TraditionalEncryptionSettings as parameters to ArchiveEntrySettings.
  • Use Archive.Save(FileStream) method for creating the archive.

系統要求

Before running the conversion example code, make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, Mono and COM Interop.
  • Development environment like Microsoft Visual Studio.
  • Aspose.Tasks for .NET DLL referenced in your project.

鎖定 ZIP 存檔 - C# 代碼示例

using (FileStream zipFile = File.Open(dataDir + "CompressWithTraditionalEncryption_out.zip", FileMode.Create))
{
    using (FileStream source1 = File.Open(dataDir + "alice29.txt", FileMode.Open, FileAccess.Read))
    {
        var archive = new Archive(new ArchiveEntrySettings(null, new TraditionalEncryptionSettings("p@s$")));
        archive.CreateEntry("alice29.txt", source1);
        archive.Save(zipFile);
    }
}



常見問題解答部分

People have been asking

1. How can I unlock a password-protected zip archive?

To unlock a password-protected zip archive, you need to provide the correct password. You can use the appropriate method or property of the zip library you are using to set the password, and then extract the files from the archive using that password.

2. Can I remove or change the password of a locked zip archive?

Yes, it is possible to remove or change the password of a locked zip archive. You can use the library’s methods or properties to modify the password. Typically, you would need to provide the current password to remove it or provide the current password along with the new password to change it.

3. Is it possible to recover a forgotten password for a locked zip archive?

Recovering a forgotten password for a locked zip archive is extremely difficult, if not impossible, without specialized tools. Zip archives are designed to provide strong encryption, and forgetting the password means losing access to the contents of the archive. It is recommended to keep your passwords safe and secure to avoid such situations.

受保護的 ZIP 歸檔操作

Aspose.Zip 提供多種加密選項以進一步增強 ZIP 檔案的安全性。開發人員可以利用 AES 加密算法(例如 AES128、AES192 和 AES256)來加密存檔中的文件。這允許使用不同的密鑰長度進行更強大的加密,以滿足特定的安全要求。此外,Aspose.Zip 支持對單個存檔中的多個文件進行加密,使開發人員能夠根據他們的特定需求使用混合加密技術。憑藉這些高級加密功能,Aspose.Zip 使開發人員能夠實施強大的安全措施來保護 ZIP 存檔中的敏感數據。

其他支持的 Aspose.Zip for .NET API 功能

使用 Aspose.Zip C# 庫進行轉換、壓縮、鎖定、解鎖、解壓檔案等!

Compression (Archive compressions)
Conversions (Rar to 7Zip)
Extract (Extracting Archives)
Lock (Archive lock)
Lock (Archive unlock)
ZIP Viewer (ZIP File Viewer)
Creating Archive (Add files or folders to ZIP)