title: encryption/decryption using AES/ECB/NoPadding
body: <p>Following are my encrypt/decrypt methods:</p>
  
  <pre><code>private String decrypt_data(String encData) 
                  throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
      {
          String key = "bad8deadcafef00d";
          SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
          Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
  
          cipher.init(Cipher.DECRYPT_MODE, skeySpec);
  
          System.out.println("Base64 decoded: "+Base64.decode(encData.getBytes()).length);
          byte[] original = cipher.doFinal(Base64.decode(encData.getBytes()));
          return new String(original).trim();     
      }
  
      private String encrypt_data(String data) 
                  throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
      {
          String key = "bad8deadcafef00d";
          SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
          Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
  
          cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
  
          System.out.println("Base64 encoded: "+ Base64.encode(data.getBytes()).length);
  
          byte[] original = cipher.doFinal(Base64.encode(data.getBytes()));
          return new String(original);
      }
  </code></pre>
  
  <p>So now when I am trying to encrypt, I am getting this exception: </p>
  
  <pre><code>javax.crypto.IllegalBlockSizeException: Input length not multiple of 16 bytes
      at com.sun.crypto.provider.CipherCore.finalNoPadding(CipherCore.java:854)
      at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:828)
      at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
      at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)
      at javax.crypto.Cipher.doFinal(Cipher.java:2087)
  </code></pre>
  
  <p>I have tried with cipher instance <code>AES/ECB/PKCS5Padding</code> in both encrypt and decrpt. It works only for encryption and not for decryption. I suppose padding is needed as data size is not multiple of 16bytes. 'data' byte length was printed as <code>152</code> so tried appending <code>eight</code> <code>\0</code> characters to data and then encrypt, it didn't work either. </p>