
一个适用于 Python 的自包含加密库
.. image:: https://github.com/Legrandin/pycryptodome/workflows/Integration%20test/badge.svg :target: https://github.com/Legrandin/pycryptodome/actions
.. image:: https://badge.fury.io/py/pycryptodome.svg :target: https://pypi.org/project/pycryptodome
PyCryptodome 是一个自包含的 Python 包,提供底层密码学原语:一次 pip install,无需系统库,并提供从 AES 和 RSA 到 HPKE、KangarooTwelve 和后量子 ML-DSA 的广泛且一致的 API。
它支持 Python 3.9 及更高版本,以及 PyPy。
安装方式如下::
pip install pycryptodome
所有模块都安装在 Crypto 包下。
.. code-block:: python
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key = get_random_bytes(32)
cipher = AES.new(key, AES.MODE_GCM) # a random nonce is generated
ciphertext, tag = cipher.encrypt_and_digest(b"attack at dawn")
receiver = AES.new(key, AES.MODE_GCM, nonce=cipher.nonce)
plaintext = receiver.decrypt_and_verify(ciphertext, tag) # raises ValueError if tampered
.. note::
直到 3.x 版本,该库还以 pycryptodomex 项目的形式发布,安装在 Cryptodome 包下。
从 4.0 版本开始,pycryptodomex 不再发布,Crypto 是唯一的包名。
如需迁移,请将导入语句中的 Cryptodome 替换为 Crypto。
有关算法和格式的完整列表,请参阅 features page。
其他所有内容,请参阅 homepage。
如有安全问题,请发送电子邮件至 [email protected]。
所有代码均可从 GitHub_ 下载。
.. _homepage: https://www.pycryptodome.org
.. _features page: https://www.pycryptodome.org/src/features
.. _GitHub: https://github.com/Legrandin/pycryptodome