本文实例讲述了Python基于pycrypto实现的AES加密和解密算法。分享给大家供大家参考,具体如下:
一 代码
# -*- coding: UTF-8 -*-
import string
import random
from Crypto.Cipher import AES
def keyGenerater(length):
'''''生成指定长度的秘钥'''
if length not in (16, 24, 32):
return None
x = string.ascii_letters+string.digits
return ''.join([rand