diff --git a/web/pgadmin/utils/crypto.py b/web/pgadmin/utils/crypto.py index 8350f7a..c8efc99 100644 --- a/web/pgadmin/utils/crypto.py +++ b/web/pgadmin/utils/crypto.py @@ -28,12 +28,12 @@ def encrypt(plaintext, key): """ iv = Random.new().read(AES.block_size) - cipher = AES.new(pad(key), AES.MODE_CFB, iv) + cipher = AES.new(pad(key.encode('utf-8')), 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') - encrypted = base64.b64encode(iv + cipher.encrypt(plaintext)) + encrypted = base64.b64encode(iv + cipher.encrypt(plaintext.encode('utf-8'))) return encrypted @@ -51,7 +51,7 @@ def decrypt(ciphertext, key): ciphertext = base64.b64decode(ciphertext) iv = ciphertext[:AES.block_size] - cipher = AES.new(pad(key), AES.MODE_CFB, iv) + cipher = AES.new(pad(key.encode('utf-8')), AES.MODE_CFB, iv) decrypted = cipher.decrypt(ciphertext[AES.block_size:]) return decrypted diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py index 0e77de5..f182e3c 100644 --- a/web/pgadmin/utils/driver/psycopg2/connection.py +++ b/web/pgadmin/utils/driver/psycopg2/connection.py @@ -256,7 +256,7 @@ class Connection(BaseConnection): return False, gettext("Unauthorized request.") try: - password = decrypt(encpass, user.password) + password = decrypt(encpass, user.password.encode('utf-8')) # Handling of non ascii password (Python2) if hasattr(str, 'decode'): password = password.decode('utf-8').encode('utf-8')