用于聚合加密元磁盘使用的文件的工具。
file_encryptor的Python项目详细描述
这是metadisk用于聚合加密和解密的库。 文件夹。它包含内联加密和解密文件的助手方法 (不使用额外空间)和流解密。
安装
您可以使用pip:
轻松安装file-encryptor。pip install file_encryptor
用法
下面是一个使用聚合加密对文件进行内联加密的示例:
importfile_encryptor.convergencekey=convergence.encrypt_inline_file("/path/to/file",None)
您还可以指定密码短语:
importfile_encryptor.convergencekey=convergence.encrypt_inline_file("/path/to/file","rainbow dinosaur secret")
要以内联方式解密文件,需要 加密方法:
importfile_encryptor.convergencekey=convergence.encrypt_inline_file("/path/to/file","rainbow dinosaur secret")convergence.decrypt_inline_file("/path/to/file",key)
不能直接使用密码短语的原因是 源于原始密码短语和sha-256 文件。
对于流应用程序,可以使用生成器解密文件:
forchunkinconvergence.decrypt_generator("/path/to/file",key):do_something_with_chunk(chunk)
加密问题
密钥生成机制如下:
key=HMAC-SHA256(passphrase,hex(SHA256(file-contents)))
如果未给出密码短语,则使用默认值。
文件本身使用来自pycrypto的AES128-CTR加密。我们不是 指定任何iv,认为对于聚合加密 做正确的事。
测试
要运行测试,请在项目根目录中执行以下命令:
python setup.py test -a "--doctest-modules --pep8 -v tests/"
要运行具有详细覆盖率输出的测试,请执行:
coverage run setup.py test -a "--doctest-modules --pep8 -v tests/" coverage report -m --include="file_encryptor/*"