ezPyCrypto加密MS Excel文件

时间:2017-01-23 23:46:39

标签: python excel encryption password-protection

我正在尝试通过Python密码保护MS Excel文件。 到目前为止,我发现这不可能通过常见的Excel库(如openPyXL和XLSX Writer)实现。

我认为这意味着我首先需要加密它。 如果我错了或者有更好的方法,请纠正我。

密码保护位是最重要的,下面没有解决,除非很容易为此添加代码。

到目前为止,这里有我加密的内容:

from ezPyCrypto import key
file_in = r'P:\Data\sample_file.xlsx'
file_out = file_in[:-5]+'_enc.xlsx'

f_in = open(file_in, 'rb')
f_out = open(file_out,'wb')

in_str = f_in.read()
out_str = key(in_str)
f_out.write(out_str)

f_in.close()
f_out.close()

但是,我一直收到这个错误:

ImportError                               Traceback (most recent call last)
<ipython-input-36-ed5218b0d47c> in <module>()
      2 #https://github.com/sfbahr/PyCrypto-Wheels
----> 3 from ezPyCrypto import key
      4 file_in = r'P:\Data\sample_file.xlsx'
      5 file_out = file_in[:-5]+'_enc.xlsx'

C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\ezPyCrypto.py in <module>()
     70 from Crypto.Util.randpool import RandomPool
     71 from Crypto.Util.number import getPrime
---> 72 from Crypto.Cipher import ARC2, Blowfish, CAST, DES3, IDEA, RC5
     73 from Crypto.Hash import MD5
     74 

ImportError: cannot import name 'IDEA'

我尝试降级到早期版本的Crypto(回到1.0.0),但仍然遇到同样的错误,它会查找IDEA&#39;在Crypto.Cipher中。

提前致谢!

1 个答案:

答案 0 :(得分:1)

我没有找到软件包“ ezPyCrypto”,但是我尝试了以下答案:answer 3 in this page,它很好用