Python에서 프레젠테이션 암호 보호

Overview

오프닝 비밀번호는 프레젠테이션을 암호화합니다. 올바른 비밀번호가 있어야 프레젠테이션 콘텐츠를 로드하고 볼 수 있으므로 이 보호는 기밀성을 제공합니다.

오프닝 비밀번호는 쓰기 보호 비밀번호와 다릅니다. 쓰기 보호는 수정을 제한하지만 콘텐츠를 암호화하지 않으며 프레젠테이션을 로드하는 것을 방지하지 않습니다. 프레젠테이션 수정용 비밀번호를 관리하려면 Write-Protect Presentations를 참조하십시오.

아래 워크플로는 PPT와 PPTX 프레젠테이션 모두에 적용됩니다. 예제에서는 파일 기반 및 스트림 기반 동작이 중요한 경우 두 형식을 모두 사용합니다.

Encrypt a Presentation with an Opening Password

ProtectionManager.encrypt을 사용하여 오프닝 비밀번호를 지정합니다. 그런 다음 Presentation.save을 사용해 암호화된 프레젠테이션을 저장합니다.

다음 예제는 PPTX 프레젠테이션을 암호화합니다:

import aspose.slides as slides

with slides.Presentation("pres.pptx") as presentation:
    presentation.protection_manager.encrypt("open_password")
    presentation.save("encrypted-pres.pptx", slides.export.SaveFormat.PPTX)

Keep Document Properties Public

기본적으로 Aspose.Slides는 프레젠테이션 암호화 시 문서 속성을 포함합니다. 이 동작은 슬라이드 내용 암호화와 별도로 ProtectionManager.encrypt_document_properties 속성으로 제어합니다. 인덱싱, 분류, 검색 또는 문서 관리 시스템이 오프닝 비밀번호 없이 메타데이터를 읽어야 할 경우, ProtectionManager.encrypt 호출 이전에 이를 False 로 설정하십시오.

다음 예제는 내장된 문서 속성을 공개 상태로 유지하면서 PPTX 프레젠테이션을 암호화합니다:

import aspose.slides as slides

with slides.Presentation() as presentation:
    properties = presentation.document_properties
    properties.author = "Contoso Knowledge Management"
    properties.title = "Quarterly Product Roadmap"
    properties.keywords = "roadmap, planning, internal"

    presentation.slides[0].name = "Encrypted presentation content"
    presentation.protection_manager.encrypt_document_properties = False
    presentation.protection_manager.encrypt("open_password")
    presentation.save("public-properties-encrypted.pptx", slides.export.SaveFormat.PPTX)

encrypt_document_propertiesFalse 로 설정해도 슬라이드, 마스터, 레이아웃, 도형, 미디어 또는 기타 프레젠테이션 콘텐츠가 공개되는 것은 아닙니다. 이는 오직 문서 속성에만 영향을 줍니다. 암호화된 콘텐츠를 로드하지 않고 해당 속성을 읽으려면 Manage Presentation Properties를 참조하십시오.

Load an Encrypted Presentation

LoadOptions.password에 오프닝 비밀번호를 지정하고 파일을 로드할 때 옵션을 Presentation에 전달합니다. 오프닝 비밀번호가 필요하지만 제공된 비밀번호가 없거나 잘못된 경우 로드에 실패합니다.

import aspose.slides as slides

load_options = slides.LoadOptions()
load_options.password = "open_password"

with slides.Presentation("encrypted-pres.pptx", load_options) as presentation:
    # 복호화된 프레젠테이션으로 작업합니다.
    pass

Remove Encryption from a Presentation

오프닝 비밀번호로 프레젠테이션을 로드한 후 ProtectionManager.remove_encryption을 호출하고 결과를 저장합니다. 저장된 프레젠테이션은 이제 비밀번호 없이 로드할 수 있습니다.

import aspose.slides as slides

load_options = slides.LoadOptions()
load_options.password = "open_password"

with slides.Presentation("encrypted-pres.pptx", load_options) as presentation:
    presentation.protection_manager.remove_encryption()
    presentation.save("encryption-removed.pptx", slides.export.SaveFormat.PPTX)

Validate an Opening Password Before Loading

PresentationFactory.get_presentation_info를 사용하면 전체 프레젠테이션 인스턴스를 만들지 않고도 PresentationInfo를 가져올 수 있습니다. 비밀번호를 요청하거나 검증하기 전에 PresentationInfo.is_password_protected를 확인하십시오. 보호가 있으면 PresentationInfo.check_password으로 제공된 값을 검증합니다.

File-Path Workflow

다음 예제는 PPTX 파일에 대한 오프닝 비밀번호를 검증하고, 검증된 값을 LoadOptions.password에 전달한 뒤 전체 프레젠테이션을 로드합니다:

import aspose.slides as slides

file_path = "protected-presentation.pptx"
password = "open_password"
presentation_info = slides.PresentationFactory.instance.get_presentation_info(file_path)

if not presentation_info.is_password_protected:
    print("The presentation does not have an opening password.")
elif not presentation_info.check_password(password):
    print("The opening password is incorrect.")
else:
    load_options = slides.LoadOptions()
    load_options.password = password

    with slides.Presentation(file_path, load_options) as presentation:
        print("The presentation was validated and loaded successfully.")

Stream Workflow

PresentationFactory.get_presentation_info의 스트림 오버로드도 동일한 워크플로를 제공합니다. 스트림에서 전체 프레젠테이션을 로드하기 전에 스트림 위치를 재설정하십시오.

다음 예제는 PPT 파일을 사용합니다:

import aspose.slides as slides

password = "open_password"

with open("protected-presentation.ppt", "rb") as presentation_stream:
    presentation_info = slides.PresentationFactory.instance.get_presentation_info(presentation_stream)

    if not presentation_info.is_password_protected:
        print("The presentation does not have an opening password.")
    elif not presentation_info.check_password(password):
        print("The opening password is incorrect.")
    else:
        presentation_stream.seek(0)
        load_options = slides.LoadOptions()
        load_options.password = password

        with slides.Presentation(presentation_stream, load_options) as presentation:
            print("The presentation was validated and loaded successfully.")

CheckPassword Return Values

PresentationInfo.check_password는 프레젠테이션에 오프닝 비밀번호가 존재하고 제공된 비밀번호가 올바른 경우에만 True 를 반환합니다. 다음 경우에는 False 를 반환합니다:

  • 비밀번호가 올바르지 않은 경우.
  • 프레젠테이션에 오프닝 비밀번호가 없는 경우.
  • 제공된 비밀번호가 None 이거나 비어 있는 경우.

PPT와 PPTX 프레젠테이션 모두 동일하게 동작합니다.

Check Whether a Loaded Presentation Is Encrypted

올바른 비밀번호로 프레젠테이션을 로드한 후 ProtectionManager.is_encrypted를 확인하여 원본 프레젠테이션이 암호화되었는지 확인하십시오. 로드하기 전에 오프닝 비밀번호 보호를 감지하려면 위에서 설명한 대로 PresentationInfo.is_password_protected 를 사용하십시오.

import aspose.slides as slides

load_options = slides.LoadOptions()
load_options.password = "open_password"

with slides.Presentation("encrypted-pres.pptx", load_options) as presentation:
    is_encrypted = presentation.protection_manager.is_encrypted
    print("The presentation is encrypted: " + str(is_encrypted))

Security Recommendations

Password-Protect a Presentation Online

  1. Aspose.Slides Lock 애플리케이션을 엽니다.
  2. 프레젠테이션을 선택하거나 업로드합니다.
  3. 보기 보호용 비밀번호를 입력합니다.
  4. 필요에 따라 편집 보호용 별도 비밀번호를 입력합니다.
  5. 보호를 적용하고 결과 파일을 다운로드합니다.

FAQ

What is the difference between an opening password and a write-protection password?

오프닝 비밀번호는 프레젠테이션을 암호화하고 콘텐츠를 로드하려면 필요합니다. 쓰기 보호 비밀번호는 콘텐츠를 암호화하지 않고 수정만 제한합니다.

Can I validate an opening password without loading all slides?

예. 프레젠테이션 정보를 얻고, 오프닝 비밀번호 보호가 있는지 확인한 뒤 전체 프레젠테이션 인스턴스를 만들지 않고 비밀번호를 검증할 수 있습니다.

Can an application read metadata without the opening password?

예, 단지 프레젠테이션이 encrypt_document_propertiesFalse 로 설정한 경우에만 가능합니다. 이 경우 애플리케이션은 Manage Presentation Properties에 설명된 문서 속성 전용 로드 모드를 사용해야 합니다.

Do the password-checking workflows support both PPT and PPTX?

예. 파일 경로 및 스트림 기반 비밀번호 감지와 검증은 PPT와 PPTX 프레젠테이션 모두에서 동일하게 동작합니다.