Easy to Decrypt Word Document with C#, VB.NET

Word Decryption is relative to Word encryption, which is one method to protect important documents. As is known, people need to have the correct password to open one encrypted Word document. This process is also called decryption.

In this post, I want to introduce a method about how to decrypt word with C#/VB.NET.

In my example, I have a document which has been encrypted with password. The password is 123456. What I will do is to decrypt this document.

Note: I use the .NET Word component, Spire.Doc for .NET, which specializes in operating Word documents, to meet my requirement more easily and quickly. Therefore, if you want to use the following code, please add Spire.Doc for .NET dll file as reference.

Detailed Steps Shown as Following:           

  1. Load the encrypted file from computer by using document.LoadFromFile() method. Generally speaking, I just need to pass one parameter which is filename to this method. However, now, I need to send three parameters to this method for decrypting this document directly. The three parameters are file name, file format and password string.
  2. Save the decrypted document with another name and launch this new document.

Main Coding:

C#

using System;
using Spire.Doc;
using Spire.Doc.Documents;

namespace DecryptWord
{
    class Decryption
    {
        static void Main(string[] args)
        {

            //Load and Decrypt
            Document document = new Document();
            document.LoadFromFile(@”E:\work\Documents\welcome.docx”, FileFormat.Docx, “123456”);

            //Save and Launch
            document.SaveToFile(“decryption.docx”, FileFormat.Docx);
            System.Diagnostics.Process.Start(“decryption.docx”);
        }
    }
}

VB.NET:

Imports System
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace DecryptWord
    Friend Class Decryption
        Shared Sub Main(ByVal args() As String)

            ‘Load and Decrypt
            Dim document As New Document()
            document.LoadFromFile(“E:\work\Documents\welcome.docx”, FileFormat.Docx, “123456”)

            ‘Save and Launch
            document.SaveToFile(“decryption.docx”, FileFormat.Docx)
            System.Diagnostics.Process.Start(“decryption.docx”)

        End Sub
    End Class
End Namespace

After running, Document Welcome.docx will be shown without entering password. 

Download Spire.Doc for .NET Here

Related Post: How to Encrypt Word Document – C#/VB.NET 

Advertisements

Author: janewdaisy

.NET Program Beginner. Share methods about how to use C#/VB.NET to export data, operate Word, Excel, PDF and other useful skills.

1 thought on “Easy to Decrypt Word Document with C#, VB.NET”

  1. I have read so many content about the blogger lovers however this paragraph is
    really a fastidious article, keep it up.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s