环境安装
python 在 Windows下使用密码库时要安装的是pycryptodome模块
pip install pycryptodome
python 在 Linux下使用密码库时要安装的是pycrypto模块
pip install pycrypto
随机数产生
#-*- coding:utf-8 -*-
from Crypto import Random
output_bytes = Random.get_random_bytes(nLength)
AES使用
#-*- coding:utf-8 -*-
from Crypto.Cipher import AES
cipher = AES.new(bytes(key), AES.MODE_CBC, bytes(IV))
output_bytes = cipher.encrypt(bytes(input_bytes)) # 加密
output_bytes = cipher.decrypt(bytes(input_bytes)) # 解密
RSA使用
#-*- coding:utf-8 -*-
from Crypto