Skip to content

enable password protection (Word) #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 20, 2017

Conversation

mariahaubner
Copy link
Contributor

This pull request will solve #546

It enables PHPWord to create password protected docx-files which MS Word can open and unlock. It was tested on MS Word 2010.

To implement the password protection, we translated the C#-code from https://blogs.msdn.microsoft.com/vsod/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0/

The actual password-hash generation is located in /Writer/Word2007/Part/Settings.php as it is Word-specific and cannot be used for the other writers.
I hope the comments left in the code and the link to the C# source clarify what is happening. But if there are any questions or remarks, feel free to share them.

Cheers, Maria

@mariahaubner mariahaubner changed the title Feature/enable password protection enable password protection (Word) Mar 13, 2017
@crevillo
Copy link

hello, what's is the state of this? still valid pr? i tried to test with master branch but there are some conflicts.

/**
* Password encoder for microsoft office applications
*/
class PasswordEncoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maartenba @Progi1984 Would it make sense to move this class to the PHPOffice common project? I guess it could be reused in PhpSpreadsheet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to do, yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as @maartenba

Poke @MarkBaker & @PowerKiKi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Progi1984 @maartenba @MarkBaker @PowerKiKi I created a PR in Common for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually not quite sure how this should/could be used in PhpSpreadsheet...

FYI, the PR: PHPOffice/Common#15

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems indeed that pre-2013 excel sheets use a very simplistic password hashing which is completely different.
In more recent specs, it also uses something very similar to what is used in word. Not sure the algorithm is the same though.

https://www.thespreadsheetguru.com/blog/2014/8/20/understanding-excels-password-security-methodology

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PowerKiKi I see you have the pre-2013 hashing implemented already in PhpSpreadsheet/Shared/PasswordHasher, this would be a more modern password hashing mechanism

@troosan troosan added this to the v0.14.0 milestone Nov 23, 2017
@troosan troosan merged commit 200c2f1 into PHPOffice:develop Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

6 participants