加密Word文档文件 [英] Encrypt Word Document File

查看:68
本文介绍了加密Word文档文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过使用StreamReader和StreamWriter来加密文本文档来读取和更改文件内容。

但是Word,我试图先将它重命名为txt,然后打开它,然后加密无论在里面,当我解密时,它都会被破坏。

我需要解释才能在word文档文件中读取字符串。



PS:I使用我的凯撒加密方法



编辑:

我不在乎它是否弱或什么。

我只是想知道加密word文档文件的步骤。



例如我的文档里面有ABCDEFGHIJKLMNOPQRSTUVWXYZ文字。

我将使用vernam密码对其进行加密。

如何?

I was able to encrypt text documents by using StreamReader and StreamWriter to read and change the file content.
But Word, I tried to rename it to txt first, then open it, and I encrypt whatever inside, when I decrypt it, it stay corrupted.
I need explanation to read string in word document file.

PS: I use my Caesar Encryption Method

Edit :
I don't care if it's weak or what.
I just want to know the step to encrypt word document file.

For example I had word document with "ABCDEFGHIJKLMNOPQRSTUVWXYZ" text inside.
And I'm going to encrypt it using vernam cipher.
How?

推荐答案

正如大家一直指出的那样,word文档不是纯文本。



他们没有问的是你处理的word文档的格式是什么?

你在处理DOC还是DOCX文件?即它是否符合OpenXML格式?



如果您正在阅读DOC文件,那么您需要使用正确的interop / libary来提取原始文本数据然后你可以加密。 (我建议你从Word Interop开始,一个不需要安装Word的替代方案是NPOI NPOI [ ^ ],2.0测试版也支持DOCX文件)



如果您正在阅读DOCX文件,那么您需要使用OpenXML库来提取原始文本数据,然后对其进行加密并将其重新插入到文档中。微软帮助页面 [ ^ ]
As everyone keeps pointing out, a word document is not plain text.

What they have not asked is what format of word document are you processing?
Are you processing a DOC or a DOCX file? i.e. does it conform to the OpenXML format?

If you are reading a DOC file, then you need to use the correct interop/libary to extract the raw text data which you can then encrypt. (I suggest you start with the Word Interop, an alternative that doesn't require Word to be installed is NPOI NPOI[^], the 2.0 beta version also supports DOCX files)

If you are reading a DOCX file, then you need to the an OpenXML libary to extract the raw text data, and then encrypt it and insert it back into the document.Microsoft Help Page[^]


PS:我用自己的加密方法。



这是你的大错。通常情况下,除非你持有数学博士学位,否则你可以选择最不安全的加密技术。



你的第二个错误是你没有发布任何与你的加密和解密有关的代码,所以任何人都不可能告诉你你在那里做错了什么。
PS: I use my own encryption method.

There's your big mistake. Usually, unless your holding a PhD in Math, rolling your own "encryption" method is about the most insecure encryption you can come up with.

Your second mistake is that you haven't posted any code having anything to do with your "encryption" and "decryption" so it's impossible for anyone to tell you what you have done wrong there.


你错了因为Word文档不是完全文本文件;它们是二进制文件。

所以,在你的过程中
- 将扩展名更改为txt

- 将文件作为文本打开

- 将它加密,好像它是一个真正的文本文件

你破坏了它。



你需要一个二进制加密过程,它比简单的凯撒加密复杂得多。一些杰出的数学家现在已经工作并且仍然在研究这个主题。
You're wrong because Word documents are not completely text files; they are instead binary files.
So, in your process of
- change extension to txt
- open the file as a text one
- encrypt it as if it was a true text file
you are corrupting it.

You need a binary encryption process, which is far more complicated than a simple Caesar encryption. Some brilliant mathematicians have worked and still work on the subject nowadays.


这篇关于加密Word文档文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆