使用pycrypto的简单文件加密
beefish的Python项目详细描述
使用pycrypto进行简单的文件加密
安装
pip install beefish pycrypto
或者:
pip install -e git+git://github.com/coleifer/beefish.git#egg=beefish
依赖关系:
命令行选项
用法:
beefish.py [-tkedaq] in_file [out_file]
- -e-加密提供的in_file,并写入out_file
- -d-解密提供的in_file,并写入out_file
- -k-将password指定为命令行参数(如果未指定,则将 安全提示)。
- -a-使用aes-256而不是默认的“blowfish”密码。
- -t-运行测试套件
- -q-安静模式(控制测试输出的详细程度)。
示例
beefish可用于加密和解密类似于对象的文件:
from beefish import encrypt, decrypt # encrypting with open('secrets.txt') as fh: with open('secrets.enc', 'wb') as out_fh: encrypt(fh, out_fh, 'secret p@ssword') # decrypting with open('secrets.enc') as fh: with open('secrets.dec', 'wb') as out_fh: decrypt(fh, out_fh, 'secret p@ssword')
如果您愿意,可以使用快捷方式:
# encrypting encrypt_file('secrets.txt', 'secrets.enc', 'p@ssword') # decrypting decrypt_file('secrets.enc', 'secrets.dec', 'p@ssword')
您可以从命令行使用它:
beefish.py -e secrets.txt secrets.enc beefish.py -d secrets.enc secrets.dec
要使用AES-256密码而不是默认密码(即blowfish):
beefish.py -a -e secrets.txt beefish.py -a -d secrets.encrypted