密码学基础与工程实践
4 阅读
预计 3 分钟
密码学是信息安全的基石。本文介绍密码学基础知识和工程实践要点。
## 对称加密
```python
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
key = AESGCM.generate_key(bit_length=256)
aesgcm = AESGCM(key)
nonce = os.urandom(12)
encrypted = aesgcm.encrypt(nonce, b"message", None)
```
## 密码存储
```python
import argon2
ph = argon2.PasswordHasher()
hash = ph.hash("password123")
```
## 工程实践要点
- 永远不要自己实现密码算法
- 使用经过审计的库
- 密钥管理比算法选择更重要
- 随机数必须使用CSPRNG
密码学工程的核心:不要发明自己的密码算法和协议。
0 条评论 欢迎参与讨论