Protect or Encrypt a Document

The main reason to protect or encrypt a document is to apply more control over who can access the document or who can edit it. Applying protection to your documents, you avoid common risks such as copying or modifying documents without permission, as well as data leakage.

Some of the most popular formats when working with documents are Microsoft Word formats or formats that can be exported from Word. That’s why many users are interested in the same document protection options that Microsoft Word provides. Despite the complexity of these options, Aspose.Words supports most of them, so it makes it an excellent solution for working with documents.

This article describes what options Aspose.Words provides for document protection and how these options are presented in the familiar Microsoft Word user interface. In the child articles of the current section, you can learn more about the listed protection functions with all the necessary properties and methods.

Document Protection Options

Aspose.Words currently provides the document features listed in the table below. You can find the details on each of the features in the corresponding child article in the current section.

Aspose.Words protection feature Corresponding child article Corresponding MS Word feature
Read-Only “Make a Document Read-Only” Always Open Read-Only (File → Info → Protect Document)
Alternative feature: “Password to modify” (Save As → Tools → General Options → Password)
Encrypt a Document “Encrypt a Document” Encrypt with Password (File → Info → Protect Document)
Alternative feature: “Password to open” (Save As → Tools → General Options → Password)
Restrict Editing “Restrict Document Editing” Restrict Editing (File – Info – Protect Document)
Alternative feature: “Restrict Editing” (Review → Protect → Restrict Editing)
Digital Signatures “Work with Digital Signatures” Add a Digital Signature (File → Info → Protect Document)

See Also


FAQ

  1. Q: How can I encrypt a Word document with a password using Aspose.Words for C++?
    A: Load the document, call Protect with the ReadOnly protection type and provide the opening password, then save the file. Example:

    System::SharedPtr<Aspose::Words::Document> doc = System::MakeObject<Aspose::Words::Document>(u"input.docx");
    doc->Protect(Aspose::Words::Protection::ProtectionType::ReadOnly, u"", u"MyOpenPassword");
    doc->Save(u"encrypted.docx");
    
  2. Q: How do I make a document read‑only without requiring a password?
    A: Use the Protect method with the ReadOnly protection type and pass an empty string for the password. The document can be opened by anyone but cannot be edited.

    System::SharedPtr<Aspose::Words::Document> doc = System::MakeObject<Aspose::Words::Document>(u"input.docx");
    doc->Protect(Aspose::Words::Protection::ProtectionType::ReadOnly, u"", u"");
    doc->Save(u"readonly.docx");
    
  3. Q: How can I restrict editing to comments or tracked changes only?
    A: Choose the appropriate ProtectionTypeComments or TrackedChanges—when calling Protect. This limits the user to adding comments or using tracked changes, respectively.

    // Restrict to comments only
    doc->Protect(Aspose::Words::Protection::ProtectionType::Comments, u"", u"");
    // Restrict to tracked changes only
    doc->Protect(Aspose::Words::Protection::ProtectionType::TrackedChanges, u"", u"");
    
  4. Q: How do I add a digital signature to a document with Aspose.Words for C++?
    A: Use DigitalSignatureUtil::Sign, providing the document, the path to a PKCS#12 certificate, and the certificate password.

    System::SharedPtr<Aspose::Words::Document> doc = System::MakeObject<Aspose::Words::Document>(u"input.docx");
    Aspose::Words::DigitalSignatureUtil::Sign(doc, u"mycert.pfx", u"certPassword");
    doc->Save(u"signed.docx");
    
  5. Q: How can I apply a license to remove evaluation limitations?
    A: Create a License object and call SetLicense with the path to your .lic file before using any Aspose.Words functionality.

    System::SharedPtr<Aspose::Words::License> license = System::MakeObject<Aspose::Words::License>();
    license->SetLicense(u"Aspose.Words.CPP.lic");
    // Now the library works in licensed mode