title: OpenSSL Encrypt-Decrypt with CryptoJS
body: <p>I have a problem to generate encryption in JS,
  I've the encryption generator in PHP like this :</p>
  <pre><code>$secret_key = 'thisIsK3y';
  $secret_iv  = 'tHis1s1v';
      
  $output         = false;
  $encrypt_method = &quot;AES-256-CBC&quot;;
  $key            = hash( 'sha256', $secret_key );
  $iv             = substr( hash( 'sha256', $secret_iv ), 0, 16 );
      
  if( $action == 'e' ) 
  {
     $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
  }
  else if( $action == 'd')
  {
      $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
  }
      
  return $output;
  </code></pre>
  <p>then I tried to translanguage to JS on React using CryptoJS :</p>
  <pre><code>import sha256 from &quot;crypto-js/sha256&quot;;
  import Base64 from &quot;crypto-js/enc-base64&quot;;
  import AES from &quot;crypto-js/aes&quot;;
  
  let secret_key = &quot;thisIsK3y&quot;;
  let secret_iv = &quot;tHis1s1v&quot;;
              
  let output = false;
  let encrypt_method = &quot;AES-256-CBC&quot;;
  let key = sha256(secret_key);
  let iv = String(sha256(secret_iv)).substr(0, 16);
       
  if (action == &quot;e&quot;) { // encrypt action
     output = AES.encrypt(&quot;test&quot;, Utf8.parse(key), {
              iv: Utf8.parse(iv),
     }).toString();
  
     alert(Base64.parse(output));
  }
  </code></pre>
  <p>then the alert show me this encryption : <strong>fd0337c029ad25c240316a1d61db9144</strong>, then I try to decrypt in my php.but it's show me plain text seems like non-printable ascii</p>
  <blockquote>
  <p>b&quot;}¦7▀À4█ÍØ█ù6ÒM§Ú¡]ÙW[¸^8&quot;</p>
  </blockquote>
  <p>and there is PHP notice :</p>
  <blockquote>
  <p>PHP Notice:  iconv(): Detected an illegal character in input string in
  /var/www/html/blabla/vendor/symfony/var-dumper/Dumper/AbstractDumper.php
  on line 203</p>
  </blockquote>
  <p>Anyone can help me out ?</p>