DOCX Encryption in C# and VB.NET

DOCX encryption enables you to securely protect the content of your Word document (DOCX) from unwanted viewers.

Following example shows how to load encrypted DOCX file and how to save document as encrypted DOCX file.

Input and output password should be specified in the appropriate text box. If password is empty, file won't be decrypted / encrypted.

Screenshot

DOCX Encryption Screenshot

See the full code below, use RUN EXAMPLE to execute.

Upload your file (Drag files here)

1using System;
2using GemBox.Document;
3using GemBox.Document.Drawing;
4using System.IO;
5using System.Linq;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        string inputPassword = "inpass";
16        string outputPassword = "outpass";
17
18        var document = DocumentModel.Load("DocxEncryption.docx", new DocxLoadOptions() { Password = inputPassword });
19
20        document.Save("DOCX Encryption.docx", new DocxSaveOptions() { Password = outputPassword });
21    }
22}
1Imports System
2Imports GemBox.Document
3Imports GemBox.Document.Drawing
4Imports System.IO
5Imports System.Linq
6
7Module Samples
8
9    Sub Main()
10
11        ' If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
13
14        Dim inputPassword As String = "inpass"
15        Dim outputPassword As String = "outpass"
16
17        Dim document = DocumentModel.Load("DocxEncryption.docx", New DocxLoadOptions With {.Password = inputPassword})
18        document.Save("DOCX Encryption.docx", New DocxSaveOptions With {.Password = outputPassword})
19
20    End Sub
21
22End Module

Check next sample or find out more about GemBox.Document and GemBox Software.