.NET Word Security-Modify Word Password in C# and Visual Basic

Generally speaking, we must open an encrypted Word document with a correct password and then do other tasks on this document. However, there are lots of password crackers so that the simple password cannot protect document any more. Therefore, it is better to modify password during a certain period. And now, I will introduce a solution to change Word password in C# and Visual Basic.

Because I will use a .NET Word component, Spire.Doc for .NET in this solution, so its dll file has been added as reference in my project at the beginning. Then, modify password step by step.

Initialize a Document(String fileName, String password) constructor instance from specified document. Because the original document is encrypted so the parameter string password is necessary to open document.

Invoke Encrypt(String password) method of Document class to set a new password to  replace the original one.  

Invoke SaveToFile(String fileName) to save this document and then launch it. After debugging, you can find that the original password cannot open document but the new can.

C#

using Spire.Doc;

namespace EncryptionSettings

{

    class Program

    {

        static void Main(string[] args)

        {

            //Load Encrypted Word

            Document doc = new Document(@”E:\Work\Documents\WordDocuments\Card.docx”, “123456”);

            //Modify Password

            doc.Encrypt(“abcxyz”);

            //Save and Launch

            doc.SaveToFile(“EncryptionSettings.docx”);

            System.Diagnostics.Process.Start(“EncryptionSettings.docx”);

        }

    }

}

Visual Basic

Imports Spire.Doc

Namespace EncryptionSettings

    Friend Class Program

        Shared Sub Main(ByVal args() As String)

            ‘Load Encrypted Word

            Dim doc As New Document(“E:\Work\Documents\WordDocuments\Card.docx”, “123456”)

            ‘Modify Password

            doc.Encrypt(“abcxyz”)

            ‘Save and Launch

            doc.SaveToFile(“EncryptionSettings.docx”)

            System.Diagnostics.Process.Start(“EncryptionSettings.docx”)

        End Sub

    End Class

End Namespace

What’s more, if you don’t want to encrypt document any more, invoke RemoveEncryption() method of Document class to open document without password.

Download Spire.Doc for .NET Here

P.S. The .NET Office component, Spire.Office for .NET can be used to realize this function as well.

Advertisements

One thought on “.NET Word Security-Modify Word Password in C# and Visual Basic

  1. modern dining baxton studio says:

    Hey would you mind letting me know which hosting company you’re working with?

    I’ve loaded your blog in 3 different browsers and
    I must say this blog loads a lot quicker then most.
    Can you suggest a good hosting provider at a reasonable price?
    Many thanks, I appreciate it!

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