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


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])]

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM