title: PHP sending encrypted data via the URL
body: <p>I'm trying to send encrypted data over the url to another site (using <code>file_get_contents("anotherUrl.php?hash=$encryptedString")</code>. The problem is, sometimes, the encryption contains some special characters, like +, and this causes the decryption to fail.</p>
  
  <p>Here are my encryption / decryption methods:</p>
  
  <pre><code>public function encrypt($string, $key)
  {
      return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
  }
  
  public function decrypt($encrypted, $key)
  {
      return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
  }
  </code></pre>
  
  <p>Here's an example encrypted string which contains a <code>+</code>, and I'm guessing that this causes the decryption to fail.</p>
  
  <p><code>oWCrVPaS+5GbxcQFc0fulUk/zRAkDD60av4zlPiWskE=</code></p>
  
  <p>Any ideas how I should solve this? I've tried to do <code>urlencode()</code> and <code>urldecode()</code> on the hash, however that also seems to cause the encryption to break. Is there a way to change the encryption algorithm to get it to only return url safe characters?</p>