title: Rijndael 256 on PHP encryption difficulties
body: <p>I have to pass a value and have it encrypted to the following spec:</p>
  
  <p>"256-bit key length, 256-bit block length, 32-byte blocks, ECB mode, with
  ASCII encoding (encrypted data is expected to be provided as a string
  with each character having been converted to a 2-byte HEX value)"</p>
  
  <p>However I must be missing something. This is for verification purposes with a webservice but I keep getting rejected due to a decryption failure.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>$key = '1324mykey';
  $string = 'Ron Swanson';
  
  // 1. Encrypt the string with the key using Rijndael 256 in ECB mode
  $td = mcrypt_module_open('rijndael-256', '','ecb', '');
  $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
  mcrypt_generic_init($td, $key, $iv);
  $encrypted_string = mcrypt_generic($td, $string);
  
  // 2. Base64 encode my string
  $encrypted_string = base64_encode($encrypted_string);
  
  // 3. Convert each character of encrypted_string to it's 2-byte HEX value 
  $hex='';
  for ($i=0; $i &lt; strlen($encrypted_string); $i++)
  {
      $hex .= dechex(ord($encrypted_string[$i]));
  }
  
  // Now $encrypted_string should match up with the recipe, but it isn't. 
  $encrypted_string = $hex;
  </code></pre>
  
  <p>I'm hoping there's something basic in the encryption requirements that I'm missing in my step 1 of my process.</p>