Skip to main content

Encrypt Presentations

  • 2 minutes to read

The DevExpress Presentation API allows you to encrypt PowerPoint presentations and open presentations that are already encrypted.

Use the EncryptionOptions class to specify presentation encryption settings. Pass an EncryptionOptions object to the Presentation.encrypt() method.

The following example encrypts a presentation with a password and strong encryption:

package presentation;

import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

import java.io.FileOutputStream;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try(Presentation presentation =
                    new Presentation(Files.readAllBytes(Path.of("Presentation.pptx")))) {

            // Specify an encryption password.
            EncryptionOptions options = new EncryptionOptions("password");

            // Encrypt the presentation.
            presentation.encrypt(options);

            Path outputDir = Path.of("output");
            Files.createDirectories(outputDir);

            // Save the encrypted presentation.
            try (FileOutputStream fileStream = new FileOutputStream(
                    outputDir.resolve("EncryptedPresentation.pptx").toFile())) {

                presentation.saveDocument(fileStream);
            }
        }
    }
}

The EncryptionOptions(password) constructor uses EncryptionType.STRONG encryption.

Use the EncryptionOptions(password, type) constructor to specify the encryption type explicitly:

EncryptionOptions options = new EncryptionOptions("password", EncryptionType.STRONG);
presentation.encrypt(options);

Load an Encrypted Presentation

Create a LoadOptions object with the specified password and document type. Pass the LoadOptions object to the Presentation constructor to load an encrypted presentation.

Note

The Presentation API cannot determine the format of encrypted files. You must call the LoadOptions.setDocumentFormat() method to specify the document format explicitly.

The following code snippet loads an encrypted presentation:

package presentation;

import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {

        LoadOptions loadOptions = new LoadOptions();
        loadOptions.setPassword("password");
        loadOptions.setDocumentFormat(DocumentFormat.PPTX);

        try(Presentation presentation =
                    new Presentation(
                            Files.readAllBytes(Path.of("EncryptedPresentation.pptx")),
                            loadOptions)) {

                // ...
        }
    }
}

Encryption Types

Use the EncryptionType enumeration to specify the encryption type.

Value Description
STRONG Agile encryption for Open XML files. The encryption data uses an XML EncryptionInfo structure. The default encryption algorithm is AES-256, and the hashing algorithm is SHA-512. Binary files use RC4 CryptoAPI encryption.
COMPATIBLE Standard encryption for Open XML files. The encryption data uses a binary EncryptionInfo structure. The default encryption algorithm is AES-128, and the hashing algorithm is SHA-1.

Encryption Password

The EncryptionOptions constructor requires a non-empty password. The API throws an exception if you pass null or an empty string.

Note

Store presentation passwords securely. Do not hard-code passwords in production applications.

Remove Encryption

Call the Presentation.removeEncryption() method to remove encryption from a presentation.

presentation.removeEncryption();
See Also