Python3 AES加解密(AES/ECB/PKCS5Padding)

Deadly 提交于 2020-01-13 05:16:02
class AesEncry(object):
	key = "wwwwwwwwwwwwwwww"  # aes秘钥

	def encrypt(self, data):
		data = json.dumps(data)
		mode = AES.MODE_ECB
		padding = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16)
		cryptos = AES.new(self.key, mode)
		cipher_text = cryptos.encrypt(padding(data).encode("utf-8"))
		return base64.b64encode(cipher_text).decode("utf-8")

	def decrypt(self, data):
		cryptos = AES.new(self.key, AES.MODE_ECB)
		decrpytBytes = base64.b64decode(data)
		meg = cryptos.decrypt(decrpytBytes).decode('utf-8')
		return meg[:-ord(meg[-1])]

  

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!