since I don't have much knowledge of Python or cryptography I wasn't able to figure out the solution, but I guess the problem is with padding. This script get's and decrypts the password using two functions. I am getting an error:
ValueError: The length of the provided data is not a multiple of the block length.
Which I guess has something to do with padding.
Here are the values used by the script:
Key: 8$4Tws[14R!,0Ba|
Encrypted pass: YTj+F1oo5OUNBgKyfifN/2R2zvFLFHbXu4Te2+OvBJ7JRae1DMVJR42qK0GucmiUyTGdtQzFSUeNqitBrnJolMkxp7UMxUlHeaor
Functions:
from django.utils.encoding import force_bytes, force_text
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
@property
def password(self):
"""Password getter."""
return decrypt(self._password)
def decrypt(ct):
backend = default_backend()
key = param_tools.get_global_parameter("secret_key", app="core")
print(key)
cipher = Cipher(
algorithms.AES(force_bytes(key)), modes.ECB(), backend=backend)
ct = base64.b64decode(force_bytes(ct))
decryptor = cipher.decryptor()
clear = decryptor.update(ct) + decryptor.finalize()
return force_text(clear.rstrip(b" "))
Can you please help? Thanks