密码保护 Open XML 文字处理文档
我需要向 Open XML Wordprocessing 文档添加基本密码保护。我可以使用 COM 接口,当我有大量文档需要处理时,它非常慢;或者我可以将数据直接放入
下的 docx 文件中,速度非常快。然而,查看加密密码的要求看起来需要花费几个小时的编程时间。有人已经编写了这个算法吗?我正在用 C# 编码。
I need to add basic password protection to an Open XML Wordprocessing document. I can either use the COM interface, which is very slow when I have a large number of documents to process; or I can put the data directly in the docx file under <w:settings>
<w:documentProtection>
which is very fast. However, looking at the requirements to encrypt the password looks like it will take hours of programming. Does anyone have this algorithm already coded? I'm coding in C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是完整的代码片段。它为您提供了一个命令行实用程序来锁定和解锁Word文件(我认为解锁文件也会删除密码保护,尽管我没有尝试这样做)。
您需要 OpenXML Format SDK 2.0 才能运行此程序,可在此处获取:http://www.microsoft.com/downloads/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en,以及对 DocumentFormat.OpenXml 的引用你的项目。
here's a full code snippet. It gives you a command line utility to lock and unlock Word files (unlocking the file will - I think - also remove the password protection, although I did not try this).
You need OpenXML Format SDK 2.0 to run this, available here: http://www.microsoft.com/downloads/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en, and a reference to DocumentFormat.OpenXml in your project.
我有类似@Brij 的东西,希望获得密码哈希的算法。随后我在MSDN论坛上发现了一些不完整的代码,并且还发现Word 2007的密码保护很容易被绕过。所以现在我只是放入随机哈希值和盐,这样包括我在内的任何人都不知道实际的密码。这足以防止意外更改;鉴于不可能阻止有意的改变,我不会让它变得更安全。
I had something similar to @Brij and was hoping to get the algorithm for the password hash. I subsequently found some incomplete code on the MSDN forum, and also discovered that the Word 2007 password protection is very easily got around. So for now I'm just putting a random hash and salt in so no one, including me, knows the actual password. That's enough effort to prevent accidental changing; and given it's impossible to prevent intentional changing, I'm not going to make it any more secure.