title: Eclipse : key on Android AES encryption and decryption
body: <p>I just want to ask.</p>
  
  <p>I have SMS application with AES encryption for android on eclipse, but I had a problem.</p>
  
  <p>The problem is when I put the key in less than 16 characters, the message can not be encrypted. but if the key is 16 characters, the message can be encrypted.</p>
  
  <p>I want to insert the key, regardless of the amount. The key can be generated to 16 characters, to get 128 bit. So, how the code is supposed to solve that problem?</p>
  
  <p>Thanks in advance - I hope you can help me.</p>
  
  <pre><code>public class AES {
      public static String encrypt(String message, String key){
          try {
              SecretKeySpec KS = new SecretKeySpec(key.getBytes(), "AES");
              Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
              cipher.init(Cipher.ENCRYPT_MODE, KS);
              byte[] encrypted = cipher.doFinal(message.getBytes());      
              return Base64.encodeToString(encrypted, Base64.NO_PADDING);
          } catch (Exception e) {
               return "ERROR:"+e.getMessage();
          }
      }
  
      public static String decrypt(String chiperText, String key){
          try {
  
              SecretKeySpec KS = new SecretKeySpec(key.getBytes(), "AES");
              Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
              cipher.init(Cipher.DECRYPT_MODE, KS);
              byte[] decrypted = cipher.doFinal(Base64.decode(chiperText, Base64.NO_PADDING));
              return new String(decrypted);
          } catch (Exception e) {
               return "ERROR";
          }
      }
  </code></pre>