#: Electronic Code Book (ECB). See `blockalgo.MODE_ECB`.
MODE_ECB = 1#: Cipher-Block Chaining (CBC). See `blockalgo.MODE_CBC`.
MODE_CBC = 2#: Cipher FeedBack (CFB). See `blockalgo.MODE_CFB`.
MODE_CFB = 3#: This mode should not be used.
MODE_PGP = 4#: Output FeedBack (OFB). See `blockalgo.MODE_OFB`.
MODE_OFB = 5#: CounTer Mode (CTR). See `blockalgo.MODE_CTR`.
MODE_CTR = 6#: OpenPGP Mode. See `blockalgo.MODE_OPENPGP`.
MODE_OPENPGP = 7#: Size of a data block (in bytes)
block_size = 16#: Size of a key (in bytes)
key_size = ( 16, 24, 32 )
加密代码
defencrypt(self, text):
pad = 16 - len(text) % 16# 设置最好字符为16位
text = text + pad * chr(pad)
cryptor = AES.new(self.key, self.mode, self.iv) # 创建一个加密对象
ciphertext = cryptor.encrypt(text) # 加密字符串return base64.b64encode(ciphertext) # base64加密显示