AES的ECB模式加密方法 :param key: 密钥 :param data:被加密字符串(明文) :return:密文
(key, data)
| 90 | |
| 91 | |
| 92 | def aesEncrypt(key, data): |
| 93 | ''' |
| 94 | AES的ECB模式加密方法 |
| 95 | :param key: 密钥 |
| 96 | :param data:被加密字符串(明文) |
| 97 | :return:密文 |
| 98 | ''' |
| 99 | key = key.encode('utf8') |
| 100 | # 字符串补位 |
| 101 | data = pad(data) |
| 102 | cipher = AES.new(key, AES.MODE_ECB) |
| 103 | # 加密后得到的是bytes类型的数据,使用Base64进行编码,返回byte字符串 |
| 104 | result = cipher.encrypt(data.encode()) |
| 105 | encodestrs = base64.b64encode(result) |
| 106 | enctext = encodestrs.decode('utf8') |
| 107 | return enctext |
| 108 | |
| 109 | |
| 110 | def aesDecrypt(key, data): |