title: How to check Python's AES decrypt error?
body: <p>I'm using python to encrypt and decrypt files. When file encrypted, then try to decrypt like this:</p>
  
  <pre><code>from Crypto.Cipher import AES
  from Crypto import Random
  def decrypt(in_file, out_file, pwd, key_len=32):
      bs = AES.block_size
      salt = in_file.read(bs)[len('Salted__'):]
      key, iv = derive_keyiv(pwd, salt, key_len, bs)
      cipher = AES.new(key, AES.MODE_CBC, iv)
      next_chunk = ''
      finished = False
      try:
          while not finished:
              chunk, next_chunk = next_chunk, cipher.decrypt(in_file.read(1024*bs))
              if len(next_chunk) == 0:
                  padding_len = ord(chunk[-1])
                  chunk = chunk[:-padding_len]
                  finished = True
              out_file.write(chunk)
          return True, None
      except Exception as e:
          return False, e
  </code></pre>
  
  <p>But if the password input error, the <code>decrypt</code> still decrypt <code>in_file</code> and write to <code>out_file</code> and no exception throw.</p>
  
  <p>How to check the password error during decrypt?</p>