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.

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.

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?
Like it?
Published: December 13, 2018 | Modified: September 3, 2020 | Author: Damir Stipinovic