与openssl兼容的对称加密和解密。
opencrypt的Python项目详细描述
安装
您可以从存储库中获取最新的.whl文件并通过pip安装它,或者只需键入:
pip install opencrypt
如果你想从源代码构建,那么。
git clone https://github.com/EbryxLabs/opencrypt
cd opencrypt/
python setup.py install
您将为python安装一个名为opencrypt
的包。
加密/解密
您可以使用ebcrypt
工具加密/解密数据。(AES-256加密)
例如,要加密,可以执行以下操作:
ebcrypt <my-file.json> -e --new
# encrypts myfile.json using newly created crypto-secure key. Keys will be written to _keys file.
ebcrypt <my-file.json> -e
# encrypts using keys in AES_KEY, AES_IV environment variable.
对于解密,您需要在环境变量中有AES_KEY
和AES_IV
密钥。
ebcrypt <my-file.json> -d
This is an optional step in case you want to decode your encrypted data explicitly for manual checking. Program decrypts your encrypted config file automatically.
您可以通过键入密码工具获得详细帮助。
ebcrypt -h
OpenSSL兼容性
openssl实用程序完成的加密可以由ebcrypt
实用程序解密,反之亦然。例如,可以使用openssl进行加密,如下所示。
openssl aes-256-cbc -a -e -K <hex-key> -iv <hex-iv> -in <input-file> -out <output-file>
hex-key
和hex-iv
应替换为十六进制格式的实际键。使用在openssl中使用的相同密钥,可以使用ebcrypt
进行解密,如下所示。
ebcrypt <encrypted-file> -d
# AES_KEY environment variable should hold <hex-key>.
# AES_IV environment variable should hold <hex-iv>.
类似地,您可以使用ebcrypt
加密,并使用openssl解密内容,前提是您使用相同的密钥。
代码使用
您也可以通过导入适当的模块在自己的代码中使用它。
import opencrypt
opencrypt.encrypt_file(filename, new_keys=False)
opencrypt.decrypt_file(filename, write_to_file=True, is_ciphertext=False)