title: How to encrypt AES in C# with CryptoJS
body: <p>I'm trying for some time to encrypt a message in AES that use a C# app , but it never works . Can someone help me?</p>
  <p>Javascript</p>
  <pre><code>const cryptojs = require(&quot;crypto-js&quot;);
  
  cryptojs.AES.decrypt( ciphertext, &quot;gpubphkxqdrkizxgyomipluuyfkvhnci&quot;);
  
  </code></pre>
  <p>C#</p>
  <pre><code>public static string Encrypt(string plainText, string keyString) {
              byte[] cipherData;
              Aes aes = Aes.Create();
              aes.Key = Encoding.UTF8.GetBytes(keyString);
              aes.Mode = CipherMode.CBC;//ECB and CBC
              aes.Padding = PaddingMode.PKCS7;
              //aes.BlockSize = 4;
              //aes.KeySize = 128 / 8;
              aes.GenerateIV();
              ICryptoTransform cipher = aes.CreateEncryptor(aes.Key, aes.IV);
  
              using (MemoryStream ms = new MemoryStream()) {
                  using (CryptoStream cs = new CryptoStream(ms, cipher, CryptoStreamMode.Write)) {
                      using (StreamWriter sw = new StreamWriter(cs)) {
                          sw.Write(plainText);
                      }
                  }
                  cipherData = ms.ToArray();
              }
  
              byte[] combinedData = new byte[aes.IV.Length + cipherData.Length];
              Array.Copy(aes.IV, 0, combinedData, 0, aes.IV.Length);
              Array.Copy(cipherData, 0, combinedData, aes.IV.Length, cipherData.Length);
              
              return Convert.ToBase64String(combinedData);
          }
  </code></pre>