title: AES encrypt/decrypt on Android doesn't run
body: <p>I need help on encryption/decryption on Android application.</p>
  
  <p>I explain the situation. I'm actually wrote an application that used content generated and encrypted by an iPhone application.</p>
  
  <p>And for securisation, the user provide his own passphrase to correctly encrypt/decrypt data between different platform...</p>
  
  <p>But, I encount a problem with the encryption/decryption of this passphrase on Android.</p>
  
  <p>I have two functions:</p>
  
  <pre><code>public byte[] crypt(String pStringToCrypt) throws Exception{
  
      byte[] key = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      System.arraycopy(this.passphrase.getBytes(), 0, key, 0, this.passphrase.getBytes().length);
      SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
  
      Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
      byte[] encrypted = cipher.doFinal(pStringToCrypt.getBytes());
      return encrypted;
  
  }
  </code></pre>
  
  <p>for the crypting of String, and this function:</p>
  
  <pre><code>public String decrypt(byte[] pCryptedStringtoDecrypt) throws Exception{
      byte[] key = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      System.arraycopy(this.passphrase.getBytes(), 0, key, 0, this.passphrase.getBytes().length);
      SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
  
      Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
      byte[] encrypted = pCryptedStringtoDecrypt;
      cipher.init(Cipher.DECRYPT_MODE, skeySpec);
      byte[] original = cipher.doFinal(encrypted);
      String originalString = new String(original);
      return originalString;
  }
  </code></pre>
  
  <p>for the decrypting of String.</p>
  
  <p>When I use the crypt method to encrypt data, I haven't error and the string was encrypted:</p>
  
  <pre><code>encrypted = [26, 119, -108, -24, 81, -128, 18, 35, -96, 10, -38, 69, 111, 40, 109, 107]
  </code></pre>
  
  <p>If I try to transform this byte into a string, I obtain this string:</p>
  
  <pre><code>encryptedString = "w��Q�#�\n�Eo(mk"
  </code></pre>
  
  <p>I think the crypting phase was good.
  Now when I try to decrypt this encrypted String, the application crashed:</p>
  
  <pre><code>javax.crypto.IllegalBlockSizeException: last block incomplete in decryption
      at org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:711)
      at javax.crypto.Cipher.doFinal(Cipher.java:1090)
      at org.vincentsaluzzo.lightrpc.common.security.AES256.decrypt(AES256.java:61)
      at com.vincentsaluzzo.LoginBox.model.SettingsManager.getUserPassphrase(SettingsManager.java:67)
      at com.vincentsaluzzo.LoginBox.mainActivity.onCreate(mainActivity.java:26)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
      at android.app.ActivityThread.access$1500(ActivityThread.java:117)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:123)
      at android.app.ActivityThread.main(ActivityThread.java:3647)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:507)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
      at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>And I don't understand why this error appear...</p>
  
  <p><strong>Do you have some solutions ? or some explanation for me ?</strong></p>