title: How to use decrypted AES key and execute php script with it's result
body: <p>i currently have a php script that decrypt a password stored in mysql then connect to imap, so far the decryption works great, i can even echo the result and it does return the correct password but for some reason imap is not connecting.. </p>
  
  <p>here is what i have</p>
  
  <pre><code>$email_pass = $sql['EMAIL_PASS'];
  
  //Decrypt Account password.
  
  function encrypt_decrypt($action, $string) {
  $output = false;
  
  $encrypt_method = "AES-256-CBC";
  $secret_key = 'ksdkjdksdk';
  $secret_iv = 'sdfdfdfdf';
  
  // hash
  $key = hash('sha256', $secret_key);
  
  // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
  $iv = substr(hash('sha256', $secret_iv), 0, 16);
  
  if( $action == 'decrypt' ){
      $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  }
  
  return $output;
  }
  
  $dec_pass = encrypt_decrypt('decrypt', $email_pass);
  
  echo $dec_pass; // this echo the correct password.
  
  
  //connect to imap
  
  $i = @imap_open("{{$server}:$port/$con_type}$eml_from", $account_uname, $dec_pass);
  </code></pre>
  
  <p>Imap is failing to connect. if i manually type in the password, it works. any suggestions?</p>