Decryption "pad block corrupted" error ???

by WoodManEXP » Thu, 18 Feb 2010 23:04:30 GMT


Sponsored Links
 Hello,

Anyone know what night be causing a "pad block corrupted" exception to
be raised with decryption on Android? Here is the scenario:

1. On Windows Java app (NetBeans) read a small file, encrypt its
contents and write it as a new encrypted file.
2. adb push the encrypted file to an Android
3. On Android, open the encrypted file and try to decrypt using same
cipher parameters as set on the Windows side and it gets the "pad
block corrupted" error.

(Running the decryption code on within the Windows Java app decrypts
OK, no "pad block corrupted" error)


Thank you for any ideas!


Here are the relevant code fragments with the trying/catching removed
for clarity.


On Windows Java app (NetBeans)

        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom secureRandom = new
SecureRandom("MyKey".getBytes());
        kgen.init(128, secureRandom);
        SecretKey skey = kgen.generateKey();
        rawKey = skey.getEncoded();
        SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES");
        cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

        FileOutputStream fileOutputStream = new FileOutputStream(new
File("filename"));
        CipherOutputStream cipherOutputStream = new
CipherOutputStream(fileOutputStream, cipher);

        int numRead = 0;
        byte[] buf = new byte[1024];
        while ((numRead = iS.read(buf)) >= 0) // iS is an input stream
        {
            cipherOutputStream.write(buf, 0, numRead);
        }
        cipherOutputStream.close();


Use ADB to push the encrypted file to the Android


On Android

        String cryptKey = "MyKey";
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom secureRandom = new
SecureRandom(cryptKey.getBytes());
        kgen.init(128, secureRandom);
        SecretKey skey = kgen.generateKey();
        rawKey = skey.getEncoded();
        SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES");
        cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);


        FileInputStream fileInputStream = new FileInputStream("filename");
        CipherInputStream cipherInputStream = new
CipherInputStream(fileInputStream, cipher);
        int numRead;
        byte[] buf = new byte[1024];
        try {
                while ((numRead = cipherInputStream.read(buf)) >= 0)
                {
                    if (retStr==null)
                                retStr = new String(buf, 0, numRead);
                        else
                                retStr = retStr.concat(new String(buf, 0, 
numRead));
                }
                cipherInputStream.close();
                } catch (IOException e1) {

                        // *************
                        // This exception is raised with message "pad block 
corrupted"
                        // *************

                }

--



Other Threads

1. (WTA) Native IM di spica samdroidmod 1.0.3

Friends,

Ada yg ud coba IM native di samdroid 1.0.3?
Punya saya ym nya gak pernah bisa login nih. Dulu waktu jc4 standar bisa
login.

Best Regards,
David Haryanto
david.harya...@gmail.com
*sent from my white spica

-- 
"Indonesian Android Community [id-android]" 

2. bmgr not working?

I'm trying to test out the new BackupManager class so I've been trying
to play around with the sample. For some reason I cannot get the bmgr
tool to work with the BackupRestoreActivity sample application
included in Android 2.2. What I tried was I started
BackupRestoreActivity, changed the inputs and typed in "adb -e shell
bmgr backup com.example.android.backuprestore":


05-24 18:57:47.100: VERBOSE/BRActivity(1107): Checkbox toggled:
android.widget.check...@43dce740
05-24 18:57:47.149: VERBOSE/BRActivity(1107): NEW STATE: mayo=true
tomato=false filling=2130968579
05-24 18:57:47.570: VERBOSE/BRActivity(1107): Checkbox toggled:
android.widget.check...@43dcf3c0
05-24 18:57:47.570: VERBOSE/BRActivity(1107): NEW STATE: mayo=true
tomato=true filling=2130968579
05-24 18:57:48.451: VERBOSE/BRActivity(1107): New radio item selected:
2130968577
05-24 18:57:48.460: VERBOSE/BRActivity(1107): NEW STATE: mayo=true
tomato=true filling=2130968577
05-24 18:57:57.590: DEBUG/AndroidRuntime(1328): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
05-24 18:57:57.860: DEBUG/AndroidRuntime(1328): --- registering native
functions ---
05-24 18:57:58.849: DEBUG/AndroidRuntime(1328): Shutting down VM
05-24 18:57:58.879: DEBUG/jdwp(1328): adbd disconnected


Followed by "adb -d shell bmgr run":

05-24 18:57:58.889: INFO/AndroidRuntime(1328): NOTE: attach of thread
'Binder Thread #3' failed
05-24 18:58:04.400: DEBUG/AndroidRuntime(1340): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
05-24 18:58:04.400: DEBUG/AndroidRuntime(1340): CheckJNI is ON
05-24 18:58:04.669: DEBUG/AndroidRuntime(1340): --- registering native
functions ---
05-24 18:58:05.549: WARN/BackupManagerService(60): Backup pass but
e=true p=false
05-24 18:58:05.569: DEBUG/AndroidRuntime(1340): Shutting down VM
05-24 18:58:05.569: DEBUG/jdwp(1340): adbd disconnected
05-24 18:58:05.611: INFO/AndroidRuntime(1340): NOTE: attach of thread
'Binder Thread #3' failed
05-24 18:58:19.215: DEBUG/SntpClient(60): request time failed:
java.net.SocketException: Address family not supported by protocol


Then I changed the fillings in the activity again and typed in "adb -d
shell bmgr restore com.example.android.backuprestore". In the console
I see the output:

Unable to restore package com.example.android.backuprestore
done

and in the android logs:


05-24 18:58:49.660: VERBOSE/BRActivity(1107): New radio item selected:
2130968579
05-24 18:58:49.700: VERBOSE/BRActivity(1107): NEW STATE: mayo=true
tomato=true filling=2130968579
05-24 18:58:53.489: DEBUG/AndroidRuntime(1366): >>>>>>>>>>>>>>
AndroidRuntime START <<<<<<<<<<<<<<
05-24 18:58:53.489: DEBUG/AndroidRuntime(1366): CheckJNI is ON
05-24 18:58:53.750: DEBUG/AndroidRuntime(1366): --- registering native
functions ---
05-24 18:58:54.630: VERBOSE/LocalTransport(60): finishRestore()
05-24 18:58:54.671: DEBUG/AndroidRuntime(1366): Shutting down VM
05-24 18:58:54.690: DEBUG/jdwp(1366): adbd disconnected
05-24 18:58:54.724: INFO/AndroidRuntime(1366): NOTE: attach of thread
'Binder Thread #3' failed

Is anybody else having the same problem?


-- 

3. Certain apps not being shown in Android Market?

4. Nubie di Pasar Malam

5. Cara update Recovery RO

6. GridView - setting selection to last item also loads first item

7. regrading invisible( hide ) running service