<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Documentation – Protect or Encrypt a Document in Java</title>
    <link>https://docs.aspose.com/words/java/protect-or-encrypt-a-document/</link>
    <description>Recent content in Protect or Encrypt a Document in Java on Documentation</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    
	  <atom:link href="https://docs.aspose.com/words/java/protect-or-encrypt-a-document/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Java: Make a Document Read-Only in Java</title>
      <link>https://docs.aspose.com/words/java/make-a-document-read-only/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://docs.aspose.com/words/java/make-a-document-read-only/</guid>
      <description>
        
        
        &lt;p&gt;Sometimes, you may have a document that needs a review, but you do not want reviewers to randomly modify your content. Aspose.Words allows you to make the permission of your document read-only so that the content can be copied or read, but not modified. This will prevent content from being removed or added to your document.&lt;/p&gt;


&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

Applying the read-only option to your document does not prevent someone from creating a new copy of it and saving it with another name.
&lt;/div&gt;

&lt;p&gt;This article explains how to make a document read-only.&lt;/p&gt;



  &lt;h2 id=&#34;how-to-make-a-document-read-only&#34;&gt;
    How to Make a Document Read-Only
  &lt;/h2&gt;
&lt;p&gt;Aspose.Words has the public class &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/writeprotection/&#34;&gt;WriteProtection&lt;/a&gt; that specifies write protection settings for a document. You do not create instances of this class directly.&lt;/p&gt;
&lt;p&gt;Write protection shows whether the author has recommended opening a document as read-only and/or requiring a password to modify the document.&lt;/p&gt;
&lt;p&gt;Aspose.Words allows you to make a document read-only to restrict editing by using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/writeprotection/#getReadOnlyRecommended&#34;&gt;ReadOnlyRecommended&lt;/a&gt; property and the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/writeprotection/#setPassword-java.lang.String&#34;&gt;SetPassword&lt;/a&gt; method.&lt;/p&gt;


&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

&lt;p&gt;In Microsoft Word, you can create a Read-Only document in a similar way using both:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;“Always Open Read-Only” (File → Info → Protect Document)&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Password to modify&amp;rdquo; (Save As → Tools → General Options → Password)&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;



&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

&lt;p&gt;Users can also restrict document editing by selecting &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/protectiontype/&#34;&gt;ProtectionType&lt;/a&gt; as &lt;strong&gt;ReadOnly&lt;/strong&gt;, but this is another feature that provides more advanced protection capabilities. There is such a function in Microsoft Word, respectively, it is implemented in Aspose.Words.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ProtectionType&lt;/strong&gt; will be described in detail in one of the following articles – “Restrict Document Editing”.&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;ReadOnlyRecommended&lt;/strong&gt; property is password-secured, so if you do not set a password before applying the &lt;strong&gt;ReadOnlyRecommended&lt;/strong&gt; property, then other users can simply open the document as if it were unprotected. You access the document protection settings and set a write protection password via the &lt;strong&gt;SetPassword&lt;/strong&gt; method.&lt;/p&gt;


&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

Note that the password being set is just a property in a document that can be removed if the document properties are accessed. Accordingly, such a password is not a guarantee of the document security.
&lt;/div&gt;

&lt;p&gt;If you need to check if a document has a write protection password that restricts it from editing, you can use the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/writeprotection/#isWriteProtected&#34;&gt;IsWriteProtected&lt;/a&gt; property.&lt;/p&gt;
&lt;p&gt;The following code example shows how to make a document read-only:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ProtectDocument-ReadOnlyProtection.java&#34;&gt;&lt;/script&gt;




  &lt;h2 id=&#34;remove-read-only-restriction&#34;&gt;
    Remove Read-Only Restriction
  &lt;/h2&gt;
&lt;p&gt;If you do not want a user to open your document as read-only, you can simply set the &lt;strong&gt;ReadOnlyRecommened&lt;/strong&gt; property to &lt;em&gt;false&lt;/em&gt; or select &lt;strong&gt;ProtectionType&lt;/strong&gt; as &lt;strong&gt;NoProtection&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The following code example shows how to remove read-only access for a document:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ProtectDocument-RemoveReadOnlyRestriction.java&#34;&gt;&lt;/script&gt;

&lt;hr&gt;



  &lt;h2 id=&#34;faq&#34;&gt;
    FAQ
  &lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How do I make a document read‑only with Aspose.Words for Java?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Load the document, obtain its &lt;code&gt;WriteProtection&lt;/code&gt; object via &lt;code&gt;document.getProtection()&lt;/code&gt;, set &lt;code&gt;setReadOnlyRecommended(true)&lt;/code&gt;, optionally call &lt;code&gt;setPassword(&amp;quot;yourPassword&amp;quot;)&lt;/code&gt;, and then save the document. The &lt;code&gt;ReadOnlyRecommended&lt;/code&gt; flag tells Word to open the file in read‑only mode.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Can I require a password to modify the document while still allowing read‑only access?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Yes. After enabling &lt;code&gt;ReadOnlyRecommended&lt;/code&gt;, call &lt;code&gt;writeProtection.setPassword(&amp;quot;modifyPassword&amp;quot;)&lt;/code&gt;. Users can open the file without a password, but any attempt to edit will prompt for the password you supplied.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How can I verify whether a document is write‑protected?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Use the &lt;code&gt;WriteProtection&lt;/code&gt; object&amp;rsquo;s &lt;code&gt;isWriteProtected()&lt;/code&gt; property. It returns &lt;code&gt;true&lt;/code&gt; if a password has been set or if &lt;code&gt;ReadOnlyRecommended&lt;/code&gt; is enabled.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How do I remove the read‑only recommendation or any write protection from a document?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Set &lt;code&gt;writeProtection.setReadOnlyRecommended(false)&lt;/code&gt; and optionally &lt;code&gt;writeProtection.setPassword(null)&lt;/code&gt;. You can also change the protection type to &lt;code&gt;ProtectionType.NO_PROTECTION&lt;/code&gt; before saving. This restores normal editing capabilities.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

      </description>
    </item>
    
    <item>
      <title>Java: Encrypt a Document in Java</title>
      <link>https://docs.aspose.com/words/java/encrypt-a-document/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://docs.aspose.com/words/java/encrypt-a-document/</guid>
      <description>
        
        
        &lt;p&gt;Encryption is the process that translates readable text to meaningless sequences of bytes so it can only be read by the person who has the decryption key or the secret code. This process plays an important role in securing your content. It helps to encode the content, verify the origin of a document, prove that the content has not been modified after it was sent, and ensure that the data from the document is safe.&lt;/p&gt;
&lt;p&gt;This article explains how Aspose.Words allows you to encrypt a document and how to check if a document has encryption or not.&lt;/p&gt;



  &lt;h2 id=&#34;encrypt-with-password&#34;&gt;
    Encrypt with Password
  &lt;/h2&gt;
&lt;p&gt;To encrypt a document, use the &lt;strong&gt;Password&lt;/strong&gt; property to provide a password that functions as an encryption key. This will modify the content of your document and make it unreadable. The encrypted document will require to have this password entered before it can be opened.&lt;/p&gt;


&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

You can find the appropriate &lt;strong&gt;Password&lt;/strong&gt; property for the required format. Each document save format has a corresponding class containing save options for this format. For example, the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/docsaveoptions/#getPassword&#34;&gt;Password&lt;/a&gt; property in the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/docsaveoptions/&#34;&gt;DocSaveOptions&lt;/a&gt; class for DOC, or the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/ooxmlsaveoptions/#getPassword&#34;&gt;Password&lt;/a&gt; property in the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/ooxmlsaveoptions/&#34;&gt;OoxmlSaveOptions&lt;/a&gt; class for DOCX, DOCM, DOTX, DOTM, and FlatOpc.
&lt;/div&gt;



&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

Note that only certain document formats support encryption. For example, RTF does not support encryption.
&lt;/div&gt;

&lt;p&gt;The table below lists the formats and encryption algorithms supported by Aspose.Words:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Supported Encryption while Loading&lt;/th&gt;
&lt;th&gt;Supported Encryption while Saving&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;DOC, DOT&lt;/td&gt;
&lt;td&gt;XOR encryption40-bit RC4 EncryptionCryptoAPI RC4 Encryption&lt;/td&gt;
&lt;td&gt;RC4 Encryption (40-bit)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DOCX, DOTX, DOCM, DOTM, FlatOPC, FlatOpcTemplate, FlatOpcMacroEnabled, FlatOpcTemplateMacroEnabled&lt;/td&gt;
&lt;td&gt;ECMA-376 Standard EncryptionECMA-376 Agile Encryption&lt;/td&gt;
&lt;td&gt;ECMA-376 Standard Encryption (AES128 + SHA1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ODT, OTT&lt;/td&gt;
&lt;td&gt;ODF Encryption (Blowfish/AES)&lt;/td&gt;
&lt;td&gt;ODF Encryption (AES256 + SHA256)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDF&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;RC4 Encryption (40/128 bit)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The following code example shows how to encrypt a document with a password:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/821ff3a1df0c75b2af641299b393fb60.js?file=encrypt-document-with-password.java&#34;&gt;&lt;/script&gt;




  &lt;h2 id=&#34;check-if-a-document-is-encrypted&#34;&gt;
    Check If a Document Is Encrypted
  &lt;/h2&gt;
&lt;p&gt;In some cases, you may have an unreadable document and want to be sure that the document is encrypted and not corrupted or compressed.&lt;/p&gt;
&lt;p&gt;To detect if a document is encrypted and if a password is required, you can use the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/fileformatinfo/#isEncrypted&#34;&gt;IsEncrypted&lt;/a&gt; property of the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/fileformatinfo/&#34;&gt;FileFormatInfo&lt;/a&gt; class. This property will also allow you to perform some action before loading a document, for example, informing a user to provide a password.&lt;/p&gt;
&lt;p&gt;The following code example shows how to detect the document encryption:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/821ff3a1df0c75b2af641299b393fb60.js?file=verify-encrypted-document.java&#34;&gt;&lt;/script&gt;




  &lt;h2 id=&#34;open-a-document-with-or-without-a-password&#34;&gt;
    Open a Document With or Without a Password
  &lt;/h2&gt;
&lt;p&gt;When we have made sure that a document is encrypted, we can try to open this document without a password, which should lead to an exception.&lt;/p&gt;
&lt;p&gt;The following code example shows how to try opening an encrypted document without a password:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/821ff3a1df0c75b2af641299b393fb60.js?file=load-encrypted-document-without-password.java&#34;&gt;&lt;/script&gt;

&lt;p&gt;After we have seen that an encrypted document cannot be opened without a password, we can try to open it by entering the password.&lt;/p&gt;
&lt;p&gt;The following code example shows how to try opening an encrypted document with a password:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/821ff3a1df0c75b2af641299b393fb60.js?file=load-save-encrypted-document.java&#34;&gt;&lt;/script&gt;

&lt;hr&gt;



  &lt;h2 id=&#34;faq&#34;&gt;
    FAQ
  &lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How do I encrypt a Word document with a password using Aspose.Words for Java?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Use the appropriate save‑options class for the target format (e.g., &lt;code&gt;DocSaveOptions&lt;/code&gt; for DOC or &lt;code&gt;OoxmlSaveOptions&lt;/code&gt; for DOCX) and set its &lt;code&gt;setPassword(&amp;quot;yourPassword&amp;quot;)&lt;/code&gt; method before calling &lt;code&gt;Document.save&lt;/code&gt;. The document will be saved encrypted and will require the password to open.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Which file formats support encryption when saving with Aspose.Words for Java?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; DOC, DOCX, DOCM, DOTX, DOTM, FlatOPC, ODT, OTT, and PDF support encryption. Formats such as RTF do &lt;strong&gt;not&lt;/strong&gt; support encryption. Each format uses its own set of supported algorithms (e.g., RC4 for DOC, ECMA‑376 AES128 for DOCX, AES256 for ODT, RC4 for PDF).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How can I determine whether a document is encrypted before loading it?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Create a &lt;code&gt;FileFormatInfo&lt;/code&gt; instance by calling &lt;code&gt;FileFormatUtil.detectFileFormat(filePath)&lt;/code&gt;. Then check the &lt;code&gt;isEncrypted()&lt;/code&gt; property. If it returns &lt;code&gt;true&lt;/code&gt;, the document is encrypted and you must supply the password when loading.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; What exception is thrown if I try to open an encrypted document without providing a password?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Aspose.Words throws a &lt;code&gt;IncorrectPasswordException&lt;/code&gt;. Catch this exception to prompt the user for the correct password or to handle the error gracefully.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Can I choose a different encryption algorithm for a specific format?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Yes. Each save‑options class exposes algorithm‑specific properties (e.g., &lt;code&gt;setEncryptionAlgorithm(EncryptionAlgorithm.AES256)&lt;/code&gt; for ODT or &lt;code&gt;setEncryptionAlgorithm(EncryptionAlgorithm.RC4_128)&lt;/code&gt; for PDF). Set the desired algorithm before saving the document.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

      </description>
    </item>
    
    <item>
      <title>Java: Restrict Document Editing in Java</title>
      <link>https://docs.aspose.com/words/java/restrict-document-editing/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://docs.aspose.com/words/java/restrict-document-editing/</guid>
      <description>
        
        
        &lt;p&gt;Sometimes you may need to limit the ability to edit a document and only allow certain actions with it. This can be useful to prevent other people from editing sensitive and confidential information in your document.&lt;/p&gt;
&lt;p&gt;Aspose.Words allows you to restrict editing a document by setting a restriction type. In addition, Aspose.Words also enables you to specify write protection settings for a document.&lt;/p&gt;
&lt;p&gt;This article explains how to use Aspose.Words to select a restriction type, how to add or remove protection, and how to make unrestricted editable regions.&lt;/p&gt;



  &lt;h2 id=&#34;select-editing-restriction-type&#34;&gt;
    Select Editing Restriction Type
  &lt;/h2&gt;
&lt;p&gt;Aspose.Words allows you to control the way you restrict the content using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/protectiontype/&#34;&gt;ProtectionType&lt;/a&gt; enumeration parameter. This will enable you to select an exact type of protection such as the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;AllowOnlyComments&lt;/li&gt;
&lt;li&gt;AllowOnlyFormFields&lt;/li&gt;
&lt;li&gt;AllowOnlyRevisions&lt;/li&gt;
&lt;li&gt;ReadOnly&lt;/li&gt;
&lt;li&gt;NoProtection&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All types are password-secured, and if this password is not entered correctly, a user will not be able to legally change the content of your document. Thus, if your document is returned to you without a requirement to provide the necessary password, this is a sign that something is wrong.&lt;/p&gt;
&lt;p&gt;If you did not set a password when choosing the security type, other users can simply ignore the protection of your document.&lt;/p&gt;


&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

Note that the password being set is just a property in a document that can be removed if the document properties are accessed. Accordingly, such a password is not a guarantee of the document security. The &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/document/#unprotect&#34;&gt;Unprotect&lt;/a&gt; method shows just that.
&lt;/div&gt;




  &lt;h2 id=&#34;add-document-protection&#34;&gt;
    Add Document Protection
  &lt;/h2&gt;
&lt;p&gt;Adding protection to your document is a simple process, as all you need to do is apply one of the protection methods detailed in this section.&lt;/p&gt;
&lt;p&gt;Aspose.Words allows you to protect your documents from changes using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/document/#protect-int&#34;&gt;Protect&lt;/a&gt; method. This method is not a security feature and does not encrypt a document.&lt;/p&gt;


&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

&lt;p&gt;In Microsoft Word, you can restrict editing in a similar way using both:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Restrict Editing (File → Info → Protect Document)&lt;/li&gt;
&lt;li&gt;Alternative feature – “Restrict Editing” (Review → Protect → Restrict Editing)&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;

&lt;p&gt;The following code example shows how to add password protection to your document:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ProtectDocument-PasswordProtection.java&#34;&gt;&lt;/script&gt;

&lt;p&gt;The following code example shows how to restrict editing in a document so only editing in form fields is possible:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ProtectDocument-AllowOnlyFormFieldsProtect.java&#34;&gt;&lt;/script&gt;




  &lt;h2 id=&#34;remove-document-protection&#34;&gt;
    Remove Document Protection
  &lt;/h2&gt;
&lt;p&gt;Aspose.Words allows you to remove protection from a document with simple and direct document modification. You can either remove the document protection without knowing the actual password or provide the correct password to unlock the document by using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/document/#unprotect&#34;&gt;Unprotect&lt;/a&gt; method. Both removing ways have no difference.&lt;/p&gt;
&lt;p&gt;The following code example shows how to remove protection from your document:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ProtectDocument-RemoveDocumentProtection.java&#34;&gt;&lt;/script&gt;




  &lt;h2 id=&#34;specify-unrestricted-editable-regions&#34;&gt;
    Specify Unrestricted Editable Regions
  &lt;/h2&gt;
&lt;p&gt;You can restrict editing of your document and at the same time allow changes to selected parts of it. So, anyone who opens your document will be able to access these unrestricted parts and make changes to the content.&lt;/p&gt;
&lt;p&gt;Aspose.Words allows you to mark the parts that can be changed in your document using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/documentbuilder/#startEditableRange&#34;&gt;StartEditableRange&lt;/a&gt; and &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/documentbuilder/#endEditableRange&#34;&gt;EndEditableRange&lt;/a&gt; methods.&lt;/p&gt;
&lt;p&gt;The following code example shows how to mark the whole document as read-only and specify editable regions in it:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ProtectDocument-UnrestrictedEditableRegions.java&#34;&gt;&lt;/script&gt;

&lt;p&gt;You can also choose different document editing restrictions for different sections.&lt;/p&gt;
&lt;p&gt;The following code example shows how to add a restriction for the entire document, and then remove the restriction for one of the sections:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ProtectDocument-UnrestrictedSection.java&#34;&gt;&lt;/script&gt;

&lt;hr&gt;



  &lt;h2 id=&#34;faq&#34;&gt;
    FAQ
  &lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How do I apply password protection to a document?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Use the &lt;code&gt;Document.protect(ProtectionType, password)&lt;/code&gt; method, passing the desired &lt;code&gt;ProtectionType&lt;/code&gt; and a string password. The password is stored in the document and is required to remove or change the protection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Can I remove protection without knowing the password?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Yes. Call &lt;code&gt;Document.unprotect()&lt;/code&gt; without arguments; this removes protection regardless of the password. Use the overload &lt;code&gt;unprotect(String password)&lt;/code&gt; only when you want to verify the password before removing protection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Which restriction type allows users to fill only form fields?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Use &lt;code&gt;ProtectionType.ALLOW_ONLY_FORM_FIELDS&lt;/code&gt; when calling &lt;code&gt;Document.protect&lt;/code&gt;. This lets users edit form fields while keeping the rest of the document read‑only.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How can I create editable regions inside a read‑only document?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; With a &lt;code&gt;DocumentBuilder&lt;/code&gt;, call &lt;code&gt;startEditableRange()&lt;/code&gt; before the region and &lt;code&gt;endEditableRange()&lt;/code&gt; after it. Content inside this range can be edited even when the document is protected with &lt;code&gt;ProtectionType.READ_ONLY&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; How can I check whether a document is currently protected?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Inspect the &lt;code&gt;Document.getProtectionType()&lt;/code&gt; property. If it returns &lt;code&gt;ProtectionType.NO_PROTECTION&lt;/code&gt;, the document is unprotected; otherwise it returns the active restriction type.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

      </description>
    </item>
    
    <item>
      <title>Java: Work with Digital Signatures in Java</title>
      <link>https://docs.aspose.com/words/java/working-with-digital-signatures/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>https://docs.aspose.com/words/java/working-with-digital-signatures/</guid>
      <description>
        
        
        &lt;p&gt;A digital signature is a technological implementation of electronic signatures to sign documents and authenticate the signer to guarantee that a document has not been modified since it was signed. Each digital signature is unique for each signer because of following the PKI protocol to generate both public and private keys. Signing a document digitally means creating a signature using the signer&amp;rsquo;s private key where a mathematical algorithm is used to encrypt the generated hash.&lt;/p&gt;
&lt;p&gt;Aspose.Words allows you to detect, count, or verify existing digital signatures, and also add a new signature to your document to find out any tampering in it. You can also remove all digital signatures from a document. Use the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/digitalsignatureutil/&#34;&gt;DigitalSignatureUtil&lt;/a&gt; class to work with digital signatures.&lt;/p&gt;
&lt;p&gt;This article explains how to do all of the above to validate the authenticity and integrity of a digital document.&lt;/p&gt;


&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

Note that you can access digital signatures of your document only when running the Java 6 version and above.
&lt;/div&gt;



&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

&lt;p&gt;&lt;strong&gt;Try online&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can try this functionality with our &lt;a href=&#34;https://products.aspose.app/words/signature&#34;&gt;Free online signature&lt;/a&gt;.&lt;/p&gt;

&lt;/div&gt;




  &lt;h2 id=&#34;supported-formats&#34;&gt;
    Supported Formats
  &lt;/h2&gt;
&lt;p&gt;Aspose.Words allows you to work with digital signatures on DOC, OOXML, and ODT documents and to sign the generated document in PDF or XPS format.&lt;/p&gt;



  &lt;h2 id=&#34;limitations-of-digital-signatures&#34;&gt;
    Limitations of Digital Signatures
  &lt;/h2&gt;
&lt;p&gt;The table below describes a few limitations that you may face while working with digital signatures through Aspose.Words, as well as some alternative options.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Limitation&lt;/th&gt;
&lt;th&gt;Alternative option&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Loss of digital signatures on a document after loading and saving it. Therefore, processing a document to a server may cause the loss of all digital signatures without a notice.&lt;/td&gt;
&lt;td&gt;Check if a document has digital signatures and take the appropriate action if any are found. For example, send an alert to the clients informing them that the document they are uploading contains digital signatures that will be lost if it is processed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Aspose.Words supports working with macros in a document. But Aspose.Words does not yet support digital signatures on macros.&lt;/td&gt;
&lt;td&gt;Export the document back to any Word format, and use Microsoft Word to add a digital signature to macros.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;



  &lt;h2 id=&#34;detect-count-and-verify-digital-signatures&#34;&gt;
    Detect, Count, and Verify Digital Signatures
  &lt;/h2&gt;
&lt;p&gt;Aspose.Words allows you to detect digital signature in a document using the the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/fileformatutil/#detectFileFormat-java.io.InputStream&#34;&gt;DetectFileFormat&lt;/a&gt; method and the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/fileformatinfo/#hasDigitalSignature&#34;&gt;HasDigitalSignature&lt;/a&gt; property. It is worth noting that such a check will only detect the fact of the signature, but not its validity.&lt;/p&gt;
&lt;p&gt;A document can be signed more than once, and this can be done by different users. To check the validity of digital signatures, you need to load them from the document using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/digitalsignatureutil/#loadSignatures-java.io.InputStream&#34;&gt;LoadSignatures&lt;/a&gt; method and use the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/digitalsignaturecollection/#isValid&#34;&gt;IsValid&lt;/a&gt; property. Also Aspose.Words allows you to count a set of all digital signatures within a document using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/digitalsignaturecollection/#getCount&#34;&gt;Count&lt;/a&gt; property.&lt;/p&gt;
&lt;p&gt;All of this provides an efficient and safe way to check a document for signatures before processing it.&lt;/p&gt;
&lt;p&gt;The following code example shows how to detect the presence of digital signatures and verify them:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/39ea49b7754e472caf41179f8b5970a0.js?file=detect-document-signatures.java&#34;&gt;&lt;/script&gt;




  &lt;h2 id=&#34;create-a-digital-signature&#34;&gt;
    Create a Digital Signature
  &lt;/h2&gt;
&lt;p&gt;To create a digital signature, you will require to load a signing certificate that confirms identity. When you send a digitally signed document, you also send your certificate and public key.&lt;/p&gt;
&lt;p&gt;Aspose.Words allows you to create X.509 certificate, a digital certificate that uses the internationally accepted X.509 PKI standard to verify that a public key belongs to the signer included inside the certificate. To do this, use the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/certificateholder/#create-byte---java.lang.String&#34;&gt;Create&lt;/a&gt; method within the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/certificateholder/&#34;&gt;CertificateHolder&lt;/a&gt; class.&lt;/p&gt;
&lt;p&gt;The next sections explain how to add a digital signature, signature line, and how to sign a generated PDF document.&lt;/p&gt;



  &lt;h3 id=&#34;sign-a-document&#34;&gt;
    Sign a Document
  &lt;/h3&gt;
&lt;p&gt;Aspose.Words allows you to sign a DOC, DOCX, or ODT document digitally using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/digitalsignatureutil/#sign-java.io.InputStream-java.io.OutputStream-com.aspose.words.CertificateHolder&#34;&gt;Sign&lt;/a&gt; method and &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/signoptions/&#34;&gt;SignOptions&lt;/a&gt; properties.&lt;/p&gt;
&lt;p&gt;The following code example shows how to sign documents using a certificate holder and sign options:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/39ea49b7754e472caf41179f8b5970a0.js?file=sign-document.java&#34;&gt;&lt;/script&gt;




  &lt;h3 id=&#34;add-a-signature-line&#34;&gt;
    Add a Signature Line
  &lt;/h3&gt;
&lt;p&gt;A signature line is a visual representation of a digital signature in a document. Aspose.Words allows you to insert a signature line using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/documentbuilder/#insertSignatureLine-com.aspose.words.SignatureLineOptions&#34;&gt;DocumentBuilder.InsertSignatureLine&lt;/a&gt; method.  You can also set the parameters for this representation using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/signaturelineoptions/&#34;&gt;SignatureLineOptions&lt;/a&gt; class.&lt;/p&gt;
&lt;p&gt;For example, the picture below shows how valid and invalid signatures can be displayed.&lt;/p&gt;
&lt;img src=&#34;valid.png&#34; alt=&#34;valid-digital-signature&#34; style=&#34;width:300px&#34;/&gt;
&lt;img src=&#34;invalid.png&#34; alt=&#34;invalid-digital-signature&#34; style=&#34;width:300px&#34;/&gt;
&lt;p&gt;Also, if a document contains a signature line and no digital signature, there is a feature to ask the user to add a signature.&lt;/p&gt;
&lt;p&gt;The following code example shows how to sign a document with a personal certificate and a specific signature line:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/39ea49b7754e472caf41179f8b5970a0.js?file=create-new-signature-line-and-set-provider-id.java&#34;&gt;&lt;/script&gt;




  &lt;h3 id=&#34;sign-a-generated-pdf-document&#34;&gt;
    Sign a Generated PDF Document
  &lt;/h3&gt;
&lt;p&gt;Aspose.Words allows you to sign and get all details of a PDF document using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/pdfdigitalsignaturedetails/&#34;&gt;PdfDigitalSignatureDetails&lt;/a&gt; properties.&lt;/p&gt;
&lt;p&gt;The following code example shows how to sign a generated PDF:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/39ea49b7754e472caf41179f8b5970a0.js?file=digitally-signed-pdf-using-certificate-holder.java&#34;&gt;&lt;/script&gt;

&lt;p&gt;The picture below demonstrates that the generated PDF document is opened in Adobe Acrobat and the digital signature is verified as present and valid.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;signed-pdf-aspose-words-java.png&#34; alt=&#34;create-digital-signed-pdf-aspose-words-java&#34;&gt;&lt;/p&gt;



  &lt;h2 id=&#34;retrieve-the-digital-signature-value&#34;&gt;
    Retrieve the Digital Signature Value
  &lt;/h2&gt;
&lt;p&gt;Aspose.Words also provides the ability to retrieve the digital signature value from a digitally signed document as a byte array using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/digitalsignature/#getSignatureValue&#34;&gt;SignatureValue&lt;/a&gt; property.&lt;/p&gt;
&lt;p&gt;The following code example shows how to obtain the digital signature value as a byte array from a document:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/39ea49b7754e472caf41179f8b5970a0.js?file=signature-value.java&#34;&gt;&lt;/script&gt;




  &lt;h2 id=&#34;remove-digital-signatures&#34;&gt;
    Remove Digital Signatures
  &lt;/h2&gt;
&lt;p&gt;Aspose.Words allows you to remove all digital signatures from a signed document using the &lt;a href=&#34;https://reference.aspose.com/words/java/com.aspose.words/digitalsignatureutil/#removeAllSignatures-java.io.InputStream-java.io.OutputStream&#34;&gt;RemoveAllSignatures&lt;/a&gt; method.&lt;/p&gt;
&lt;p&gt;The following code example shows how to load and remove digital signatures from a document:&lt;/p&gt;
&lt;script type=&#34;application/javascript&#34; src=&#34;https://gist.github.com/aspose-words-gists/39ea49b7754e472caf41179f8b5970a0.js?file=remove-signatures.java&#34;&gt;&lt;/script&gt;



&lt;div class=&#34;alert alert-primary&#34; role=&#34;alert&#34;&gt;

Note that you can not remove only one digital signature within your document.
&lt;/div&gt;

&lt;hr&gt;



  &lt;h2 id=&#34;faq&#34;&gt;
    FAQ
  &lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Do I need a licensed copy of Aspose.Words to use digital signature features?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Yes. Digital signature functionality is fully available only with a valid Aspose.Words license. In evaluation mode the library works, but certain features may be limited or watermarked.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Can I remove a single digital signature from a document?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; No. Aspose.Words can only remove all signatures at once using &lt;code&gt;RemoveAllSignatures&lt;/code&gt;. Individual signature removal is not supported.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Is it possible to sign a PDF that was generated from a Word document?&lt;br&gt;
&lt;strong&gt;A:&lt;/strong&gt; Yes. After generating the PDF, use &lt;code&gt;DigitalSignatureUtil.Sign&lt;/code&gt; with a &lt;code&gt;CertificateHolder&lt;/code&gt; and appropriate &lt;code&gt;SignOptions&lt;/code&gt; to apply a digital signature to the PDF.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

      </description>
    </item>
    
  </channel>
</rss>
