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. Android Developer Position Available

Hi Android Developers,

My name is Carl Schumacher & I am working with a major media company
on the bleeding edge looking to fill a position. If you are interested
in this position please forward me an email & we can chat. Pay is
pretty flexible for the right person.

Position:                       Senior Developer
Location:                       Los Angeles, CA



Education Requirements:
-       Business or technology college degree or higher

Experience requirements:
-       Coding and building
o       Mobile web sites
o       Software solutions for internal billing and revenue allocation
-       Solving complex technical issues for management of advertising
-       .Net expertise
-       Working and managing external, overseas development teams
-       Emerging mobile platforms like windows mobile, iPhone and Android
-       Fast learner who enjoys investigating and developing to new
technologies and platforms


Role & responsibilities:
-       Work with mobile teams to implement software solutions for managing
businesses
-       Investigate new emerging technologies and develop applications
-       Find, assess and work with overseas development teams
-       Project manage external resources and projects
-       Interface with

Carl Schumacher
Executive Recruiter
Wireless & Digital Content
Electronic Search, Inc.
5105 Tollview Dr. #245
Rolling Meadows, IL 60008
Fax (847) 506-9999
[EMAIL PROTECTED]
http://www.linkedin.com/in/wirelessexecrecruiter
http://www.electronicsearch.com
http://www.wirelesstemps.com
--~--~---------~--~----~------------~-------~--~----~

2. Android Developer Available Position

Hi Android Developers,

My name is Carl Schumacher & I am working with a major media company
on the bleeding edge looking to fill a position. If you are interested
in this position please forward me an email & we can chat. Pay is
pretty flexible for the right person.

Position:                       Senior Developer
Location:                       Los Angeles, CA



Education Requirements:
-       Business or technology college degree or higher

Experience requirements:
-       Coding and building
o       Mobile web sites
o       Software solutions for internal billing and revenue allocation
-       Solving complex technical issues for management of advertising
-       .Net expertise
-       Working and managing external, overseas development teams
-       Emerging mobile platforms like windows mobile, iPhone and Android
-       Fast learner who enjoys investigating and developing to new
technologies and platforms


Role & responsibilities:
-       Work with mobile teams to implement software solutions for managing
businesses
-       Investigate new emerging technologies and develop applications
-       Find, assess and work with overseas development teams
-       Project manage external resources and projects
-       Interface with

Carl Schumacher
Executive Recruiter
Wireless & Digital Content
Electronic Search, Inc.
5105 Tollview Dr. #245
Rolling Meadows, IL 60008
Fax (847) 506-9999
[EMAIL PROTECTED]
http://www.linkedin.com/in/wirelessexecrecruiter
http://www.electronicsearch.com
http://www.wirelesstemps.com
--~--~---------~--~----~------------~-------~--~----~

3. closing and opening application gives error

4. Emulator does not start with additional emulator command line arguments

5. Free code day for Google App Engine at Google Offices

6. dialog user input box

7. Problem on adding scrollbar to GridlView