DOCX Encryption in C# and VB.NET

DOCX encryption enables you to securely protect the content of your Word document from unwanted viewers by encrypting it with a password. The passwords are case-sensitive and they can't be empty.

Location of encryption option in Microsoft Word application

To read a protected or encrypted Word document, you'll need to provide a DocxLoadOptions.Password value.

To write a protected or encrypted Word document, you'll need to provide a DocxSaveOptions.Password value.

The following example shows how you can load an encrypted DOCX file and save it as an encrypted DOCX file with a different password in C# and VB.NET.

Encrypting and decrypting Word file of DOCX format in C# and VB.NET
Screenshot of Word document's encryption
Upload your file (Drag file here)
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        string inputPassword = "%InputPassword%";
        string outputPassword = "%OutputPassword%";

        var document = DocumentModel.Load("%InputFileName%",
            new DocxLoadOptions() { Password = inputPassword });

        document.Save("DOCX Encryption Output.docx",
            new DocxSaveOptions() { Password = outputPassword });
    }
}
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim inputPassword As String = "%InputPassword%"
        Dim outputPassword As String = "%OutputPassword%"

        Dim document = DocumentModel.Load("%InputFileName%",
            New DocxLoadOptions With {.Password = inputPassword})

        document.Save("DOCX Encryption Output.docx",
            New DocxSaveOptions With {.Password = outputPassword})

    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Document yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.