From 163cadc279cec25390a6dd0243e7491321ad8506 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Tue, 10 Apr 2018 17:12:14 +0100 Subject: [PATCH] Revert "Fix non-ASCII password decryption/encryption under Python 3" This reverts commit d0a640442cd6dc7bbfdb2647cf1775c13ad79a96. Seems to anger Python 2.7 --- web/pgadmin/utils/crypto.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/pgadmin/utils/crypto.py b/web/pgadmin/utils/crypto.py index 8350f7a1b..def3d6848 100644 --- a/web/pgadmin/utils/crypto.py +++ b/web/pgadmin/utils/crypto.py @@ -28,11 +28,11 @@ def encrypt(plaintext, key): """ iv = Random.new().read(AES.block_size) - cipher = AES.new(pad(key), AES.MODE_CFB, iv) + key = pad(key).encode('utf-8') + cipher = AES.new(key, AES.MODE_CFB, iv) # If user has entered non ascii password (Python2) # we have to encode it first - if hasattr(str, 'decode'): - plaintext = plaintext.encode('utf-8') + plaintext = plaintext.encode('utf-8') encrypted = base64.b64encode(iv + cipher.encrypt(plaintext)) return encrypted @@ -51,7 +51,8 @@ def decrypt(ciphertext, key): ciphertext = base64.b64decode(ciphertext) iv = ciphertext[:AES.block_size] - cipher = AES.new(pad(key), AES.MODE_CFB, iv) + key = pad(key).encode('utf-8') + cipher = AES.new(key, AES.MODE_CFB, iv) decrypted = cipher.decrypt(ciphertext[AES.block_size:]) return decrypted