title: AES-256-CBC Encryption/Decryption hex string using openssl in php
body: <p>I'm a noob developer and I'm trying to decrypt some data but when I use OpenSSL in PHP I received no response. Also, when trying to encrypt data OpenSSL add a block of characters.</p>
  
  <p>This is the code:</p>
  
  <pre><code>    &lt;?php
      $dataToDecrypt = hex2bin("C2E5CDFE8BBFBC7350D40538434824DD3E11520B89A5BFDE24FA064DB2EED6EA");
      $aesKey = hex2bin("E3FB8EA130722FA99266B96B77C2735C39393939393939393920202020202020");
      $iv = hex2bin("00000000000000000000000000000000");
      $result = openssl_decrypt($dataToDecrypt, 'AES-256-CBC', $aesKey, OPENSSL_RAW_DATA, $iv);
      echo bin2hex($result);
  ?&gt;
  </code></pre>
  
  <p>The <code>$result</code> is supposed to be:</p>
  
  <pre><code>C3A6149C73FFBE4EAD36DC62FE40877D17CD690F37B06058CA3D65A345CC8212
  </code></pre>
  
  <p>I've tried this on VB and even in a AES encription web page (<a href="http://aes.online-domain-tools.com/" rel="nofollow noreferrer">http://aes.online-domain-tools.com/</a>) and the result is correct. But when trying with PHP I've got no answer.</p>
  
  <p>I noticed when encrypting with the same information, the encrypted data is different. This is the code:</p>
  
  <pre><code>    &lt;?php
      $dataToEncrypt = hex2bin("C3A6149C73FFBE4EAD36DC62FE40877D17CD690F37B06058CA3D65A345CC8212");
      $aesKey = hex2bin("E3FB8EA130722FA99266B96B77C2735C39393939393939393920202020202020");
      $iv = hex2bin("00000000000000000000000000000000");
      $result = openssl_encrypt($dataToEncrypt, 'AES-256-CBC', $aesKey, OPENSSL_RAW_DATA, $iv);
      echo bin2hex($result);
  ?&gt;
  </code></pre>
  
  <p>When I encrypt the result is:</p>
  
  <pre><code>C2E5CDFE8BBFBC7350D40538434824DD3E11520B89A5BFDE24FA064DB2EED6EA3A3ED407DC78D6AF9030BAB90CB40EAD
  </code></pre>
  
  <p>I get 32 characters more than expected (<code>3A3ED407DC78D6AF9030BAB90CB40EAD</code>). When I encrypt in VB or using the web page mentioned before I don't get these 32 extra characters.</p>
  
  <p>Why is this happening? Am I missing something? I've been searching for an answer for several days. Any help is appreciated.</p>