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. Question of displaying a ProgressDialog in a joined thread

Hello, i have a question of displaying a ProgressDialog by joining the
threads. In my application, i will synchronize data with the server,
and remove the synchronized data from database. The synchronization
takes long time, so i decide to display a progressdialog during this
process. Of course i use a new thread to deal the synchronization,
here is what i use for the first time:

syncProgressDialog = ProgressDialog.show(Function.getContext(),
"Please wait...", "Synchronizing application's data...", true, false);

new Thread(new Runnable() {
        public void run() {
                synchronize();
                syncProgressDialog.dismiss();
        }
}).start();

removeData();

The problem i met with this solution is the main thread didn't launch
this thread immediately, it called the removeData before the new
Thread. Apparently the main thread don't wait the new Thread finishes
before execute the following method. So i changed this solution to :

syncProgressDialog = ProgressDialog.show(Function.getContext(),
"Please wait...", "Synchronizing application's data...", true, false);

Thread thread = new Thread(new Runnable() {
        public void run() {
                synchronize();
                syncProgressDialog.dismiss();
        }
});
thread.start();
try {
        thread.join();
}
catch (InterruptedException e) {
        e.printStackTrace();
}

removeData();

I used the join method to wait the end of synchronize thread before
removeData, there is another problem comes, the ProgressDialog didn't
display on the screen. I tried use handler:

Thread thread = new Thread(new Runnable() {
        public void run() {
                synchronize();
                handler.post(new Runnable() {
                        public void run() {
                                removeDialog();
                        }
                });
        }
});

private void removeDialog() {
        syncProgressDialog.dismiss();
}

Nothing changed, could anyone show me a sample code to display the
ProgressDialog in a joined thread or tell me which part i didn't
implemented correctly.


--~--~---------~--~----~------------~-------~--~----~

2. Error when run "helloandroid"

when i run hello android like on
http://code.google.com/android/intro/hello-android.html, my eclipse
show error like this :
                   Tag <activity> missing required attribute name.      

and on AndroidManifest.xml there is an error on line :
                  <activity class=".helloandroid"
android:label="@string/app_name">



can u help me to fix this ?

thanks before :)

--~--~---------~--~----~------------~-------~--~----~

3. Need Android consultants - Los Angeles - 3-6 months

4. Need Android consultant with Java - Los Angeles - 3 months

5. ERROR No resource identifier found for attribute 'textAlign' in package 'android'

6. EditText box of emulator cannot type in these characters

7. how to reject an incoming call