hybrid-cipher
Hybrid Encryption Mode with Public-Key Encryption and Symmetric Encryption.
Install
pip install hybrid-cipher
加密原理
加密步骤
- 生成随机32位临时密钥。
- 使用RSA公钥加密临时密钥。
- 使用临时密钥及AES GCM加密算法加密数据内容。
- 把临时密钥的密文及数据密文相关字段拼接在一起,作为整体密文。
解密步骤
- 分割密文为:临时密钥密文、数据密文相关字段。
- 使用RSA私钥解密临时密钥密文,得到临时密钥明文。
- 使用临时密钥明文及AES GCM解密算法解密数据密文相关字段,得到数据明文。
Usage
In [1]: from Crypto.PublicKey import RSA
...: from hybrid_cipher import HybridCipher
...:
...: sk = RSA.generate(1024)
In [2]:
In [2]: cipher = HybridCipher(sk)
In [3]: cipher.encrypt({"a": "b"})
Out[3]: 'LS8T8hzgCfzo9QzlJ8pO7DD+pSolam9EZIhr35gTSGQayTj2NLqPgx7T8VGbgC2EnAf7fuFN0EXNlljQt1Vg9EyUC8sAMCRCw21zGN/SQttVQFQrETtZndNw/c5pODMVeVFELKnzbw0E50IC3f4mTd38il6O7fQz9SH7zr8Lle0=.tXn5E6vUHLbufPi7gIEFJg+iZDrxOq73q3ds3ZUHFOA=.51hM5vLf4x3nmwlbKRTgwA==.DK5W89RZ9MCl220YqZo5mA==./0O4k+4zIwIGrw=='
In [4]: cipher.decrypt('LS8T8hzgCfzo9QzlJ8pO7DD+pSolam9EZIhr35gTSGQayTj2NLqPgx7T8VGbgC2EnAf7fuFN0EXNlljQt1Vg9EyUC8sAMCRCw21zGN/SQttVQFQrETtZndNw/c5pODMVeVFELKnzbw0E50IC3f4mTd
...: 38il6O7fQz9SH7zr8Lle0=.tXn5E6vUHLbufPi7gIEFJg+iZDrxOq73q3ds3ZUHFOA=.51hM5vLf4x3nmwlbKRTgwA==.DK5W89RZ9MCl220YqZo5mA==./0O4k+4zIwIGrw==')
Out[4]: {'a': 'b'}
Release
v0.1.1
- First release.
Metadata
Release files for hybrid-cipher 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hybrid_cipher-0.1.1.tar.gz | 4.5 kB | Without provenance | Details for hybrid_cipher-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hybrid_cipher-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for hybrid_cipher-0.1.1-py3-none-any.whl |
Total release size: 9.0 kB
Release files / hybrid_cipher-0.1.1.tar.gz
| Download URL | hybrid_cipher-0.1.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4533210ad2923f2348dc5fa5232da20f59b6a07acc9c61d5c1153aba0841a1cb
|
|
BLAKE2b-256 checksum How to use checksums |
fdc84fd3872e5ceb0272d85263f76c07d7e38f67eb50336f1333830efa05b02f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Release files / hybrid_cipher-0.1.1-py3-none-any.whl
| Download URL | hybrid_cipher-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22a2a45c5c85f6b0867f948694a59adb221f0c653a661ecb90d6b4910f584583
|
|
BLAKE2b-256 checksum How to use checksums |
c450094b98f54e33b71a8acf2789e0f64f2d7fdca9f1cf455cfc5099357b1117
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Security for hybrid-cipher 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.