From 45796f717d3727d10c58aea84d642ad462c7aee5 Mon Sep 17 00:00:00 2001 From: Roy <576477085@qq.com> Date: Wed, 19 Jun 2024 15:07:00 +0800 Subject: [PATCH] update aes decode --- api/terminal/terminal/apps/assets/api.py | 1 - api/terminal/terminal/common/utils.py | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/terminal/terminal/apps/assets/api.py b/api/terminal/terminal/apps/assets/api.py index 9d7c22e..b9e66d2 100644 --- a/api/terminal/terminal/apps/assets/api.py +++ b/api/terminal/terminal/apps/assets/api.py @@ -205,7 +205,6 @@ def list(self, origin_password = item['password'][len(encrypted_prefix):] origin_password = bytes.fromhex(origin_password) key = utils.md5(item['id'] + CONF.platform_encrypt_seed)[:16] - key = key.encode(encoding = "utf-8") origin_password = utils.aes_cbc_pkcs7_decrypt(origin_password, key, key) item['password'] = origin_password.decode() return datas diff --git a/api/terminal/terminal/common/utils.py b/api/terminal/terminal/common/utils.py index eb16a87..099da10 100644 --- a/api/terminal/terminal/common/utils.py +++ b/api/terminal/terminal/common/utils.py @@ -378,6 +378,8 @@ def md5(text): def aes_cbc_pkcs7_decrypt(encrypted, key, iv): + key = utils.ensure_bytes(key) + iv = utils.ensure_bytes(iv) cipher = AES.new(key, AES.MODE_CBC, iv) data = cipher.decrypt(encrypted) # pkcs7 padding @@ -389,6 +391,7 @@ def platform_encrypt(text, guid, seed): encrypted_prefix = '{cipher_a}' if not text.startswith(encrypted_prefix): key = md5(guid + seed)[:16] + key = utils.ensure_bytes(key) cipher = AES.new(key, AES.MODE_CBC, key) text = utils.ensure_bytes(text) # pkcs7 padding @@ -408,6 +411,7 @@ def platform_decrypt(text, guid, seed): encrypted_text = text[len(encrypted_prefix):] encrypted_text = bytes.fromhex(encrypted_text) key = md5(guid + seed)[:16] + key = utils.ensure_bytes(key) cipher = AES.new(key, AES.MODE_CBC, key) origin_text = cipher.decrypt(encrypted_text) origin_text = origin_text[0:-origin_text[-1]]