title: AES/CBC/PKCS#5 cookie decryption in PHP
body: <p>We are currently using web based LDAP for authentication and part of the process is to decrypt a cookie.  In the past we have used the ColdFusion code below.</p>
  
  <pre><code>&lt;cffile action="read" file="e:\keys\key.cfm" variable="thekey"&gt;
  &lt;cfset clearcookie = decrypt(evaluate("cookie.#[registered app name]#"), thekey,'AES/CBC/PKCS5Padding', 'base64')&gt;
  </code></pre>
  
  <p>We now need to do the same in PHP but for some reason my code does not seem to be working.  My cookie is currently saved under <code>$ck</code> and the key under <code>$key</code> and I do not have an IV which I hope is not needed. </p>
  
  <p>Per a post by lord_t and Sage Pay Support, I am doing the following:</p>
  
  <pre><code>$ck = substr($ck,1);
  $ck = base64_decode($ck);
  $text= (mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ck, MCRYPT_MODE_CBC,$key));
  echo $text;
  </code></pre>
  
  <p>When I run it my output is garbage which leads me to believe the algorithm is not right.  What could be the issue?  Do I need and IV?</p>
  
  <p>Again, I want to replicate what we have done in ColdFusion in the past.</p>