C#에서 ZIP 파일에 비밀번호 보호 설정하는 방법

C#에서 ZIP 파일에 비밀번호 보호 설정하는 방법

이 기본 튜토리얼은 C#에서 ZIP 파일을 암호로 보호하는 방법을 설명합니다.그것은 필요한 구성, 단계별 방법론, 그리고 효율적으로 ZIP 파일을 암호화 할 수있는 실행 가능한 코드 스니피트를 커버합니다.

암호를 보호하는 ZIP 파일의 이점

  • 확장된 보안:- 귀하의 민감한 데이터를 허가되지 않은 액세스로부터 보호합니다.

  • 사용하기 쉬운 방법:- 암호화 된 파일을 노출에 대한 두려움없이 쉽게 공유합니다.

  • 훌륭한 지원:- 대부분의 응용 프로그램 및 시스템은 암호화 된 ZIP 파일을 인식합니다.

원제 : Environment Preparation

  • Visual Studio 또는 모든 호환되는 .NET IDE를 설정합니다.
  • NuGet 패키지 관리자에서 Aspose.ZIP를 설치합니다.

단계별 암호 가이드 ZIP 파일 보호

단계 1 : 프로젝트 설정

NuGet을 사용하여 프로젝트에 Aspose.ZIP 라이브러리를 추가합니다.

Install-Package Aspose.ZIP

단계 2: 입력 파일을 업로드

당신이 압축하고 암호화하고 싶은 파일을 읽으십시오. FileStream 개체를 위한

using (FileStream source = File.Open("input.txt", FileMode.Open, FileAccess.Read))
{
    // Further processing steps will follow here
}

3단계 : 암호화 설정 설정 설정

암호화 설정을 설정, 알고리즘과 비밀번호를 포함하여, ArchiveEntrySettings 클래스 입니다

var settings = new ArchiveEntrySettings(null, new AesEcryptionSettings("p@s$", EncryptionMethod.AES256));

4단계: 암호로 보호된 ZIP 파일 만들기

이제 ZIP 파일을 만들고 특정 설정으로 저장할 수 있습니다.

using (FileStream zipFile = File.Open("PasswordAES256.zip", FileMode.Create))
{
    using (var archive = new Archive(settings))
    {
        archive.CreateEntry("input.txt", source);
        archive.Save(zipFile);
    }
}

완전한 코드 샘플 암호 보호 ZIP 파일

다음은 암호가 ZIP 파일을 보호하는 방법을 보여주는 완전한 C# 예입니다.

// Open the input file as a FileStream
using (FileStream source = File.Open("input.txt", FileMode.Open, FileAccess.Read))
{
    // Create a FileStream object for the output ZIP file
    using (FileStream zipFile = File.Open("PasswordAES256.zip", FileMode.Create))
    {
        // Set up encryption settings
        var settings = new ArchiveEntrySettings(null, new AesEcryptionSettings("p@s$", EncryptionMethod.AES256));

        // Create an empty ZIP archive
        using (var archive = new Archive(settings))
        {
            // Create an entry for the input file
            archive.CreateEntry("input.txt", source);

            // Save the encrypted ZIP file
            archive.Save(zipFile);
        }
    }
}

추가 정보

  • 암호 또는 알고리즘과 같은 암호 설정을 사용자 정의하여 보안을 향상시킵니다.
  • 또한 압축 및 파일 처리에 대한 추가 매개 변수를 설정할 수 있습니다.

결론

이 튜토리얼은 Aspose.ZIP를 사용하여 C#에서 ZIP 파일을 암호로 보호하는 방법을 보여줍니다.이 빠르고 쉬운 방법은 파일을 효율적으로 보안 할 수 있습니다.다음 작업을 위해 ZIP 파일을 추출하거나 자기 추출 파일을 만드는 것과 같은 추가 튜토리얼을 참조하십시오.

 한국어