title: AES Encryption is implemented in ECB mode but it is not security compliant. How to implement CBC mode
body: <p>I have implemented AES encryption in java, but the algorithm is not accepted by team as it is implemented in ECB mode which is not security compliant.I am very new to cryptography and Security requirements.</p>
  
  <p>Can someone please help me changing algorithm to CBC mode. I have attached my code implemented in ECB mode.</p>
  
  <pre><code>public String encrypt(String plainPwd)
  {
      byte[] outputBytes = new byte[] {};
      String returnString = "";
      try
      {
          byte[] raw = "XXXXX@XXXXXX.XXX".getBytes("UTF-8");
  
          SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
          Cipher cipher = Cipher.getInstance("AES");
          cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
  
          outputBytes = cipher.doFinal(plainPwd.getBytes("UTF-8"));
          if (null != outputBytes)
          {
              returnString = Base64Encrypter.getInstance().encode(outputBytes);
          }
          return returnString.trim();
  
      }
      catch (Exception e)
      {
          System.out.println(e);
      }
  
      return new String(outputBytes).trim();
  }
  
  public String decrypt(String encryptedPwd)
  {
      byte[] outputBytes = new byte[] {};
      try
      {
          byte[] raw = "XXXXX@XXXXXX.XXX".getBytes("UTF-8");
  
          SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
          Cipher cipher = Cipher.getInstance("AES");
          cipher.init(Cipher.DECRYPT_MODE, skeySpec);
  
          byte[] inputBytes = Base64Encrypter.getInstance().decode(encryptedPwd);
          if (null != inputBytes)
          {
              outputBytes = cipher.doFinal(inputBytes);
          }
      }
      catch (Exception e)
      {
          System.out.println(e);
      }
  
      return new String(outputBytes).trim();
  }
  </code></pre>
  
  <p>Early reply will be highly appreciated. 
  Thanks in advance</p>