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. Do the latest SDK&ADT not support Cupcake(1.5)?

I rebuilt my Android app with the latest SDK(3.0) and targeted it to
API level 10 with min SDK 3(<uses-sdk android:targetSdkVersion="10"
android:minSdkVersion="3"/>) recently.

The apk installs and works well on my old G1 with cupcake, but I can't
download it form Market with that phone after I uploaded the update .

My cupcake G1 can see my app via Market(aka. my app is not filtered
out by market), but "Not found: The requested item could not be found"
appears when the app is clicked in Market.

I notice there are some other apps that appear in Market of cupcake
but can't be downloaded. E.g. Advanced Task Killer.

I understand cupcake is really old, but it is not announced as
unsupported officially. Is it?

Are all the efforts I've made to to keep the compatibility of cupcake
not worth?

-- 

2. .rodata section

Hi,

 I have a custom library in which I'm not sure if the code & data sections 
are being mapped correctly. I see that all the C++ methods are listed under 
the .rodata section. Don't they have to be under .text? The C functions 
however are properly listed under .text. Is there any compiler/linker option 
that needs to be enabled?

The problem I'm having is, once this library is loaded (by the caller using 
dlopen), there is a crash that manifests somewhere else. 

Thanks & will appreciate a response
HV


-- 

3. 45rb test, browser android vs iPhone

4. tethering eth0 interface

5. Android Kernel Build Errors- Yaffs2 Errors

6. Networking configuration changes

7. Gingerbread enak ga sih ?