title: CryptoJS AES Encryption and Decryption
body: <p>First of all, I have 2 different systems - one in java, and one in javascript. I have an encrypted string (done in java), I also have secretKey which was used to encrypt it. I can decrypt it using this in Javascript. I know decryption result is correct. So I cant change decryption logic. Here is decryption code: </p>
  
  <pre><code>decrypt = (value) =&gt; {
    const cipher = CryptoJS.enc.Base64.parse(value);
    const dec = CryptoJS.enc.Utf8.stringify(
    CryptoJS.AES.decrypt(
        { ciphertext: cipher },
        secretKey,
        { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding }
     )
   );
   return dec;
  };
  </code></pre>
  
  <p>I am trying to encrypt the result of above to get original encrypted string in javascript. I tried to do exactly opposite of what I did in decrypt. Here is encryption code:</p>
  
  <pre><code>encrypt = (value) =&gt; {
      var encrypted = CryptoJS.enc.Utf8.parse(
          CryptoJS.AES.encrypt(
              value, secretKey,
              { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding }
          )
    );
    const cipher = CryptoJS.enc.Base64.stringify(encrypted);
    return cipher;
  </code></pre>
  
  <p>}</p>
  
  <p>I am expecting an original string which was passed in, but I am not getting same result.</p>
  
  <pre><code>let decrypted = decrypt("LJalEgQ81qUjrVzhlgFNw==");
  console.log("Decrypted:", decrypted);
  
  encrypted = encrypt(decrypted);
  console.log("Encrypted:", encrypted);
  </code></pre>
  
  <p>Any help is appreciated. Thanks in advance.</p>