Encrypt with Password

This demo uses the DevExpress Word Processing Document API to encrypt documents. You can process the sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.

You can specify the encryption type and password. Click Encrypt and Save as... dropdown button to select the output format, update the file, and download the result.

Sample document
Sample.docx



using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

Stream EncryptDocumentWithPassword(Stream inputStream, DocumentFormat outputFormat, string password, EncryptionType encryptionType) {
    using var wordProcessor = new RichEditDocumentServer();

    wordProcessor.LoadDocument(inputStream);

    var encryptionSettings = new EncryptionSettings {
        Password = password,
        Type = encryptionType
    };

    var outputStream = new MemoryStream();

    wordProcessor.SaveDocument(outputStream, outputFormat, encryptionSettings);

    outputStream.Position = 0;
    return outputStream;
}