Reputation: 7536
I am trying to password-protect an MS Excel file via Python. I found so far that this is not possible via common Excel libraries such as openPyXL and XLSX Writer.
I assume this means that I first need to encrypt it. Please correct me if I am wrong or if there is a better approach.
The password-protection bit is the most important, which is not addressed below, unless it's easy to add code to this to that effect.
So far, here's what I have for encryption:
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()
However, I keep getting this error:
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'
I tried downgrading to earlier versions of Crypto (back to 1.0.0) but keep getting the same error, which looks for 'IDEA' within Crypto.Cipher.
Thanks in advance!
Upvotes: 1
Views: 2827
Reputation: 504
I did not find the package "ezPyCrypto", But I tried this answer: answer 3 in this page and it works great
Upvotes: 1