栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python aes加密

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python aes加密

class AEScoder():
    def __init__(self,encryptKey):
        self.__encryptKey = encryptKey
        self.aes = AES.new(str.encode(self.__encryptKey), AES.MODE_ECB)  # 初始化加密器,本例采用ECB加密模式

    def add_to_16(self,s):
        while len(s) % 16 != 0:
            s += ''
        return str.encode(s)  # 返回bytes

    def encrypt(self, text):
        # AES加密
        encrypted_text = str(base64.encodebytes(self.aes.encrypt(self.add_to_16(text))), encoding='utf8').replace('n', '')  # 加密
        return encrypted_text

    def decrypt(self, encrData):
        # AES解密
        decrypted_text = str(self.aes.decrypt(base64.decodebytes(bytes(encrData, encoding='utf8'))).rstrip(b'').decode("utf8"))  # 解密
        return decrypted_text


AEScoder(self.key).encrypt(code)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/744845.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号