title: How to decrypt this CryptoJS encryption in PHP (function provided)
body: <p>(Please note that the function I reference from the provided answer didn't work so I want to modify it to make it work or please provide a suitable solution to AES encryption in VueJS and decryption in PHP (or Laravel))</p>
  <p>I have a password will be sent to Laravel API so I managed to encrypt and base64 it then send it to Laravel API. Here's the original encryption</p>
  <p><a href="https://i.stack.imgur.com/1fFsf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fFsf.png" alt="enter image description here" /></a></p>
  <p>And here's the encryption and encoding</p>
  <pre><code> var encryptedPassword = CryptoJS.AES.encrypt(&quot;123456&quot;, &quot;Secret Passphrase&quot;);
   const replacerFunc = () =&gt; {
   const visited = new WeakSet();
   return (key, value) =&gt; {
     if (typeof value === &quot;object&quot; &amp;&amp; value !== null) {
       if (visited.has(value)) {
        return;
       }
       visited.add(value);
     }
     return value;
   };
  };
  let jsonString = JSON.stringify(encryptedPassword, replacerFunc());
  let bs46encoded = btoa(unescape(encodeURIComponent(JSON.stringify(jsonString, replacerFunc()))))
  </code></pre>
  <p>I get this result</p>
  <p><code>IntcIiRzdXBlclwiOntcIiRzdXBlclwiOnt9fSxcImNpcGhlcnRleHRcIjp7XCJ3b3Jkc1wiOlsxODQ4NTYxMTAzLDE1MjkyNDgyMTUsLTEwODg3MTk1MDEsLTEyNjAyOTYzNjJdLFwic2lnQnl0ZXNcIjoxNn0sXCJrZXlcIjp7XCIkc3VwZXJcIjp7fSxcIndvcmRzXCI6Wy0yODA5NjkxMjcsNzAzNjYxOTM0LDE1Mjg5OTYxNDEsLTEwOTU5OTQ2MDYsLTY4OTMyOTM1NiwtNDQ1MDc3MjE3LC0yMDM4MDY1MTUxLC0xNzI0MjIzMzE4LC0xNTk1Nzk5MDI5LDgxOTY1NjMwMSwtMTQzNTIxMDg2NCwxODkwMDcyNTc5XSxcInNpZ0J5dGVzXCI6MzJ9LFwiaXZcIjp7XCJ3b3Jkc1wiOlstMTU5NTc5OTAyOSw4MTk2NTYzMDEsLTE0MzUyMTA4NjQsMTg5MDA3MjU3OV0sXCJzaWdCeXRlc1wiOjE2fSxcImFsZ29yaXRobVwiOntcImtleVNpemVcIjo4LFwiJHN1cGVyXCI6e1wiY2ZnXCI6e1wibW9kZVwiOntcIiRzdXBlclwiOnt9LFwiRW5jcnlwdG9yXCI6e30sXCJEZWNyeXB0b3JcIjp7fX0sXCJwYWRkaW5nXCI6e30sXCIkc3VwZXJcIjp7fX0sXCJibG9ja1NpemVcIjo0LFwiJHN1cGVyXCI6e1wia2V5U2l6ZVwiOjQsXCJpdlNpemVcIjo0LFwiX0VOQ19YRk9STV9NT0RFXCI6MSxcIl9ERUNfWEZPUk1fTU9ERVwiOjIsXCIkc3VwZXJcIjp7XCJfbWluQnVmZmVyU2l6ZVwiOjB9fX19LFwiYmxvY2tTaXplXCI6NCxcImZvcm1hdHRlclwiOnt9LFwic2FsdFwiOntcIndvcmRzXCI6WzE5NDk1NjcxNjIsMjExODc0MjAyOF0sXCJzaWdCeXRlc1wiOjh9fSI=</code></p>
  <p>In laravel</p>
  <pre><code>$objString = base64_decode($ecodedString);
  </code></pre>
  <p>And I get</p>
  <pre><code>&quot;{\&quot;$super\&quot;:{\&quot;$super\&quot;:{}},\&quot;ciphertext\&quot;:{\&quot;words\&quot;:[-1208966431,415513002,-380428285,-1848403568],\&quot;sigBytes\&quot;:16},\
  &quot;key\&quot;:{\&quot;$super\&quot;:{},\&quot;words\&quot;:[1997420112,-1528658502,-601329304,170123410,85401029,1271916135,-1899682466,856024313,-1926693888,505524620,1922976396,79922502],\&quot;sigBytes\&quot;:32},
  \&quot;iv\&quot;:{\&quot;words\&quot;:[-1926693888,505524620,1922976396,79922502],\&quot;sigBytes\&quot;:16},\&quot;algorithm\&quot;:{\&quot;keySize\&quot;:8,\&quot;$super\&quot;:{\&quot;cfg\&quot;:{\&quot;mode\&quot;:{\&quot;$super\&quot;:{},\&quot;Encryptor\&quot;:{},\&quot;Decryptor\&quot;:{}},\&quot;padding\&quot;:{},\&quot;$super\&quot;:{}},\&quot;blockSize\&quot;:4,\&quot;$super\&quot;:{\&quot;keySize\&quot;:4,\&quot;ivSize\&quot;:4,\&quot;_ENC_XFORM_MODE\&quot;:1,\&quot;_DEC_XFORM_MODE\&quot;:2,\&quot;$super\&quot;:{\&quot;_minBufferSize\&quot;:0}}}},\&quot;blockSize\&quot;:4,\&quot;formatter\&quot;:{},
  \&quot;salt\&quot;:{\&quot;words\&quot;:[3335652791,3193595722],\&quot;sigBytes\&quot;:8}}&quot;
  </code></pre>
  <p>Then</p>
  <pre><code>$this-&gt;cryptoJsAesDecrypt(&quot;Secret Passphrase&quot;, $objString);
  
  public function cryptoJsAesDecrypt($passphrase, $jsonString){
      $jsondata = json_decode($jsonString, true);
      Log::alert(&quot;jsondata&quot;);
      Log::alert($jsondata);
      $salt = hex2bin($jsondata[&quot;salt&quot;]);
      $ct = base64_decode($jsondata[&quot;ct&quot;]);
      $iv  = hex2bin($jsondata[&quot;iv&quot;]);
      $concatedPassphrase = $passphrase.$salt;
      $md5 = array();
      $md5[0] = md5($concatedPassphrase, true);
      $result = $md5[0];
      for ($i = 1; $i &lt; 3; $i++) {
          $md5[$i] = md5($md5[$i - 1].$concatedPassphrase, true);
          $result .= $md5[$i];
      }
      $key = substr($result, 0, 32);
      $data = openssl_decrypt($ct, 'aes-256-cbc', $key, true, $iv);
      Log::alert(&quot;data&quot;);
      Log::alert($data);
      return $data;
  }
  </code></pre>
  <p>$jsondata returns</p>
  <pre><code>{&quot;$super&quot;:{&quot;$super&quot;:{}},&quot;ciphertext&quot;:{&quot;words&quot;:[-1208966431,415513002,-380428285,-1848403568],&quot;sigBytes&quot;:16},
  &quot;key&quot;:{&quot;$super&quot;:{},&quot;words&quot;:[1997420112,-1528658502,-601329304,170123410,85401029,1271916135,-1899682466,856024313,-1926693888,505524620,1922976396,79922502],&quot;sigBytes&quot;:32},
  &quot;iv&quot;:{&quot;words&quot;:[-1926693888,505524620,1922976396,79922502],&quot;sigBytes&quot;:16},&quot;algorithm&quot;:{&quot;keySize&quot;:8,&quot;$super&quot;:{&quot;cfg&quot;:{&quot;mode&quot;:{&quot;$super&quot;:{},&quot;Encryptor&quot;:{},&quot;Decryptor&quot;:{}},&quot;padding&quot;:{},&quot;$super&quot;:{}},&quot;blockSize&quot;:4,&quot;$super&quot;:{&quot;keySize&quot;:4,&quot;ivSize&quot;:4,&quot;_ENC_XFORM_MODE&quot;:1,&quot;_DEC_XFORM_MODE&quot;:2,&quot;$super&quot;:{&quot;_minBufferSize&quot;:0}}}},&quot;blockSize&quot;:4,&quot;formatter&quot;:{},
  &quot;salt&quot;:{&quot;words&quot;:[3335652791,3193595722],&quot;sigBytes&quot;:8}}
  </code></pre>
  <p>But can't get other variables correctly to decrypt this encryption and find the original plain text. How can I edit this function to make it work?</p>
  <p>I try to clone this answer <a href="https://stackoverflow.com/questions/27677236/encryption-in-javascript-and-decryption-with-php#answer-64330804">Encryption in JavaScript and decryption with PHP</a></p>