title: How can I encode and decode a string with a simple passphrase in PHP?
body: <p>I thought this would be simple but I can't find a simple solution to this..</p>
  
  <p>Is there a way to encode a string and decode a string with a simple passphrase?
  somesthing like this:</p>
  
  <pre><code>$encoded = stringEncrypt('someText','simpleKey');
  echo stringDecrypt($encoded,'simpleKey'); //outputs someText;
  </code></pre>
  
  <p>I tried this but with no luck:</p>
  
  <pre><code>function lime_encrypt($data,$key)
  {
      return base_convert(bin2hex($data),16,10)  *   base_convert(bin2hex($key),16,10)  ;
  }
  
  function lime_decrypt($data,$key)
  {
      return pack("H*",base_convert($data/base_convert(bin2hex($key),16,10),10,16));
  }
  </code></pre>
  
  <p>I think this is because the multiplication doesn't returns a integer but a mathematical expression 6.28414834514E+25</p>
  
  <p>any idea how I can implement this?</p>
  
  <hr>
  
  <h2>edit</h2>
  
  <p>I reused another code I found on stack overflow and ended up with this:</p>
  
  <pre><code>function lime_encrypt($data,$key)
  {
      return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $data, MCRYPT_MODE_CBC, md5(md5($key))));
  }
  
  function lime_decrypt($data,$key)
  {
      return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($data), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
  }
  </code></pre>
  
  <p>but I end up with a Fatal error: Call to undefined function mcrypt_encrypt() using php > 5 on linux centOS.</p>
  
  <p>So I'd rather stay simple and movable to other hostings...</p>
  
  <hr>
  
  <h2>Solution?</h2>
  
  <p>At the end, I'm using this, found on a blog:</p>
  
  <pre><code>function lime_encrypt($data,$key)
  {
      return openssl_encrypt($data, 'AES-128-CBC', $key,0,'fgrgfvcfghtfdrfg');
  }
  
  function lime_decrypt($data,$key)
  {
      return openssl_decrypt($data, 'AES-128-CBC', $key,0,'fgrgfvcfghtfdrfg');
  }
  </code></pre>