Skip to content

Commit

Permalink
update aes decode
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy committed Jun 19, 2024
1 parent 39e1b50 commit 45796f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 0 additions & 1 deletion api/terminal/terminal/apps/assets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions api/terminal/terminal/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]]
Expand Down

0 comments on commit 45796f7

Please sign in to comment.