Cryptography:用于加密的Python库
Cryptography的目标是建立一个标准Python加密库。如果你曾经在工作中使用过Python加密技术,那么你很可能知道一些库,例如M2Crypto、PyCrypto或者PyOpenSSL。Cryptography库想要解决已有库中存在的一些问题:
- 缺少PyPy和Python 3支持
- 缺少维护
- 使用了差评的算法实现(例如旁路攻击side-channel attacks)
- 缺少高级(易于使用)的APIs
- 缺少AES-GCM和HKDF等算法
- 经不住测试
- 错误百出的APIs
示例
1 2 3 4 5 6 7 8 9 |
>>> from cryptography.fernet import Fernet >>> # Put this somewhere safe! >>> key = Fernet.generate_key() >>> f = Fernet(key) >>> token = f.encrypt(b"A really secret message. Not for prying eyes.") >>> token '...' >>> f.decrypt(token) 'A really secret message. Not for prying eyes.' |
github主页:https://github.com/pyca/cryptography