Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Jan 31, 2014 5:56 pm

Hello,

I am currently using Spire.Doc v4.9.6.3040. When i use Spire.Doc.Document.Protect() with a password, and then call Spire.Doc.Document.Encrypt() the following happens.
1) I am correctly prompted to enter a password when I OPEN the file in MS Word.
2) After entering the password to open the document, I can view doc.
3) When I attempt to EDIT the document, I am correctly notified that the document is protected, however I am not prompted for a password to edit to document.
4) I can bypass the document protection simply by turning it off, never being required to enter a password.

Is this a bug? Is there an alternate method for protecting and encrypting a document?

nameeri
 
Posts: 3
Joined: Fri Jan 31, 2014 4:54 pm

Mon Feb 03, 2014 4:27 am

Hi,

Thanks for your inquiry.
There is a simple demo for you
Code: Select all
Document doc = new Document();
doc.AddSection().AddParagraph().AppendText("Security Test");
doc.Protect(ProtectionType.AllowOnlyReading, "write");
doc.Encrypt("read");
doc.SaveToFile("out.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("out.docx");

After run this demo, the word document file out.docx was opened via MS-Word (Word 2010 in my computer). I got the prompt as p1.png.
Image

After entering the password "read", the file was opened. When I tried to edit it, I got the prompt in the right part of the MS-Word window, as p2.png
Image
I cliked the button "Stop Protection" and then I got a prompt as p3.png
Image
After entering the password "write", I could edit the document.
I attached also the out.docx file, you can try it with your MS-Word tool.

I ran the demo with Spire.Doc Pack Version:5.0 (version fo dll 5.0.12.30xx), you can get it from http://www.e-iceblue.com/Download/downl ... t-now.html

If you still have this problem, would you please provide us the below detailed information, which may help us to reproduce your issue and offer the solution to you quickly.

1. Dll file list (name + version), for example:
Spire.Doc.dll v4.9.32.3040
Spire.License.dll v4.9.32.3040
Spire.Pdf.dll v2.8.86.3040

2. Operation System, for example:
Windows 7 Enterprise Edition SP1 x64
Regional and Language Options

3. Project can reproduce the issue
All code about this problem, a simple project which can reproduce this problem will be better.

4. Test Document or Test data
Please provide your test document to us if convenient, it may help us reproduce your issue quickly. We promise to keep your document confidential and we will not use it for any other purpose. Besides, you could also remove the security data of your document and then send it to us.

Thanks and Regards,
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar

harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Mon Feb 03, 2014 5:29 pm

Harry thanks for the quick reply.

I am trying to put together a simple project for trouble shooting the issue but I am having trouble getting the solution built. I am taking over the project which was developed by a contractor who is no longer with our company. We purchased the Pro version of Spire.Doc however I do not have it installed on my system. Here is some more info:

I have Spire dll's as follows:

1) Spire.Doc
- Runtime Version: v4.0.30319
- Version: 4.9.6.3040
2) Spire.License
- Runtime Version: v4.0.30319
- Version: 1.3.2.40
3) Sprire.Pdf
- Runtime Version: v4.0.30319
- Version: 2.8.30.3040

Here is an overview of what we are doing to help you re produce the error:

1) Create a new Document object (doc)
2) Call doc.LoadFromFile() and open an existing template (which we use for mail merge)
3) Insert a header image
4) Call doc.MailMerge.Execute() and pass a List of objects for merging
5) Call doc.Protect() with ProtectionType.AllowOnlyReading and password to protect the document
6) Call doc.SaveToFile() with the path and FileFormat.Docx

All of the above works correctly. When I debug and check the file after step 6 above, the protection works.

Later in our code we do the following

1) Create a new Document object (doc)
2) call doc.LoadFromFile() and open the file which was created above (this is the protected file)
3) call doc.Encrypt() with a password
4) call doc.SaveToFile() with the same path and FIleFormat.Docx

For some reason, It seems like opening the file and then encrypting it breaks the protection.

I will see if these operation can be bundled together so that we are not protecting the file, then saving, then opening, then encrypting. It may be able to be condensed into a protect, encrypt and save as shown in your example.

nameeri
 
Posts: 3
Joined: Fri Jan 31, 2014 4:54 pm

Wed Feb 05, 2014 9:16 am

Hello,
Thanks for your feedback.
Have you tried the newest dll of Spire.Doc? You could get it from http://www.e-iceblue.com/Download/downl ... t-now.html.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Feb 10, 2014 3:13 pm

I was able to correct this problem by changing our code slightly.

I placed the Document.Protect() and Document.Encrypt() method calls immediately after one another and then called Document.Save(). This corrected the problem I was seeing.

nameeri
 
Posts: 3
Joined: Fri Jan 31, 2014 4:54 pm

Tue Feb 11, 2014 1:21 am

Hello,

Thanks for your feedback.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc

cron