Badpadding Exception while decrypting a video file
<p>I encryted the first 2048 bytes data with AES, and decrypting the same but the code returns error as BadPaddingException while decrypting. I don't know why? Please sugeest me the right result.</p>

<p>Thanks in advance:</p>

<p><strong>Error:</strong></p>

<pre><code>11-18 15:59:35.452: WARN/System.err(30071): javax.crypto.BadPaddingException: pad block corrupted
11-18 15:59:35.456: WARN/System.err(30071):     at org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:653)
11-18 15:59:35.456: WARN/System.err(30071):     at javax.crypto.Cipher.doFinal(Cipher.java:1116)
11-18 15:59:35.456: WARN/System.err(30071):     at com.example.Hide.HideFolderActivity.decrypt(HideFolderActivity.java:191)
11-18 15:59:35.456: WARN/System.err(30071):     at com.example.Hide.HideFolderActivity.decrypt(HideFolderActivity.java:167)
11-18 15:59:35.456: WARN/System.err(30071):     at com.example.Hide.HideFolderActivity.onCreate(HideFolderActivity.java:65)
11-18 15:59:35.456: WARN/System.err(30071):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-18 15:59:35.456: WARN/System.err(30071):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-18 15:59:35.456: WARN/System.err(30071):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-18 15:59:35.456: WARN/System.err(30071):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-18 15:59:35.456: WARN/System.err(30071):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-18 15:59:35.460: WARN/System.err(30071):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 15:59:35.460: WARN/System.err(30071):     at android.os.Looper.loop(Looper.java:123)
11-18 15:59:35.460: WARN/System.err(30071):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-18 15:59:35.460: WARN/System.err(30071):     at java.lang.reflect.Method.invokeNative(Native Method)
11-18 15:59:35.460: WARN/System.err(30071):     at java.lang.reflect.Method.invoke(Method.java:521)
11-18 15:59:35.460: WARN/System.err(30071):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-18 15:59:35.460: WARN/System.err(30071):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-18 15:59:35.460: WARN/System.err(30071):     at dalvik.system.NativeStart.main(Native Method)
11-18 15:59:35.480: WARN/InputManagerService(2501): Got RemoteException sending setActive(false) notification to pid 29873 uid 10092
</code></pre>

<p><strong>Code:</strong></p>

<pre><code>private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
        //SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(raw, "AES"), new IvParameterSpec(new byte[cipher.getBlockSize()]));
        byte[] decrypted = cipher.doFinal(encrypted);
            return decrypted;
    }
</code></pre>
