Java encryption, decryption of Word documents

For some important documents, we guarantee that the contents of the document will not be leaked, the files must always be encrypted. When viewing a file, you must enter the password correctly before opening the file. In this paper, we will show you how to use Spire.Doc for Java to set password protection for Word documents and remove passwords.

[Example 1] Word password protection setting

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class EncryptWord {

    public static void main(String[] args) {

        //Read a Word document
        Document document = new Document();
        document.loadFromFile("sample.docx");

        //Protect your documents with a password
        document.encrypt("abc-123");

        //Save document
        document.saveToFile("Encrypt.docx", FileFormat.Docx);
    }
}

File encryption result: 1.png

[Example 2] Unprotect Word password

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class DecryptWord {

    public static void main(String[] args) {

        //Read the file with the password and enter the original password to unlock it
        Document document = new Document();

        document.loadFromFile("Encrypt.docx", FileFormat.Docx, "abc-123");

        //Save document
        document.saveToFile("Decrypt.docx", FileFormat.Docx);
    }
}

When you run the program, the created file will no longer be password protected.

Recommended Posts

Java encryption, decryption of Word documents
Merge Java Word documents
RSA encryption / decryption with java 8
Java adds hyperlinks to Word documents
[Java] Realize multi-column effect of Word document
Add footnotes to Word documents in Java
[Java] Overview of Java
RSA key pair creation / encryption / decryption sample (JAVA)
Java adds and removes watermarks in word documents
KMS) Envelope encryption with openssl and java decryption
Change paragraph text color in Java Word documents
Expired collection of java
Predicted Features of Java
[Java] Significance of serialVersionUID
NIO.2 review of java
Review of java Shilber
java --Unification of comments
History of Java annotation
java (merits of polymorphism)
Java applications convert Word (DOC / DOCX) documents to PDF
Java joins and splitting table cells in Word documents
NIO review of java
[Java] Three features of Java
Summary of Java support 2018
Java reserved word summary
About an instance of java
[Java] Mirage-Basic usage of SQL
[Java] Practice of exception handling [Exception]
[Java11] Stream Summary -Advantages of Stream-
Basics of character operation (java)
4th day of java learning
[Java] Beginner's understanding of Servlet-①
Java end of month plusMonths
[Java] Summary of regular expressions
[Java] Summary of operators (operator)
[Java] Implementation of Faistel Network
[Java] Comparator of Collection class
Summary of Java language basics
[Java] Summary of for statements
Summary of Java Math class
Enumeration of all combinations Java
java (inheritance of is-a principle)
Implementation of gzip in java
Advantages and disadvantages of Java
Benefits of Java static method
[Java] Summary of control syntax
Implementation of tri-tree in Java
Summary of java error processing
[Java] Summary of design patterns
[Java] Summary of mathematical operations