From 00dc4c5a7bba18a3c4a5ecfef7b035b2ccd70d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Sat, 7 Nov 2020 08:20:08 +0100 Subject: [PATCH] Changed default encrypt to AES --- server/src/uds/core/managers/crypto.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/uds/core/managers/crypto.py b/server/src/uds/core/managers/crypto.py index c6f5c05a..79f67fef 100644 --- a/server/src/uds/core/managers/crypto.py +++ b/server/src/uds/core/managers/crypto.py @@ -176,10 +176,27 @@ class CryptoManager: return array.array('B', (s1a[i] ^ s2a[i] for i in range(len(s1a)))).tobytes() def symCrypt(self, text: typing.Union[str, bytes], key: typing.Union[str, bytes]) -> bytes: - return self.xor(text, key) + if isinstance(text, str): + text = text.encode() + if isinstance(key, str): + key = key.encode() + + return self.AESCrypt(text, key) def symDecrpyt(self, cryptText: typing.Union[str, bytes], key: typing.Union[str, bytes]) -> str: - return self.xor(cryptText, key).decode('utf-8') + if isinstance(cryptText, str): + cryptText = cryptText.encode() + + if isinstance(key, str): + key = key.encode() + + if not cryptText: + return '' + + try: + return self.AESDecrypt(cryptText, key).decode('utf-8') + except Exception: # Error decoding stored crypted password, return empty one + return '' def loadPrivateKey(self, rsaKey: str): try: