First, you are trying to use a random IV at the time of decrypt . The IV must be random when encrypting, but to decrypt, you must use the same IV used in the encryption (and therefore you must save the IV next to ciphertext , otherwise you will not be able to decrypt it) .
Second, what exactly are you trying to decipher? I do not know what library you are using, but from what I understand of your code you are using a password
field as a key (PS make sure the data type passed to the function - string or binary - is the same type expected by it ) and then you're trying to decrypt ... password
itself ?! Should your function not receive a key and a cipher [and an IV] and use the key to decrypt the cipher?
Finally, there's the problem pointed out by jsbueno : if your encryption function works with binary data (such as if expected from a Python library) and its IV / cipher are in base64, then you need to use b64decode
in IV before passing it to AES.new
and in cipher before passing it to decrypt
, and < in> maybe get the final result (binary) and put it in a convenient format to be handled by the python code (in what format was this data when it was encrypted? was another python code that encrypted, or was another language / platform? and finally: the cipher / IV were even encoded in base64?).