huntergdavis / Easy_File_Encrypt

Android - Easy File Encrypt
Other
11 stars 4 forks source link

Unable to Encrypt PDF files. #1

Open openrijal opened 11 years ago

openrijal commented 11 years ago

Hello.

I used this library to Encrypt files for a project.

I was able to Encrypt DOC and TXT files, but encryption of PDF files made the file corrupt.

Upon inspection, it seems that the file type was changed to "application/octet-stream".

Is this a known issue? Is there any solutions yet for the issue?

openrijal commented 11 years ago

Hello. It seems that, I was wrong in the first place.

The issue actually is that, when we Encrypt a PDF file, it becomes unable to open it. But, it can be Decrypted with the same seed (password) that was used to Encrypt it.

Besides that, there has been an issue with Decryption of file in Android JellyBean 4.2 (API 17) and above. The most basic work around is to add Crypto explicitly while generating the SecureRandom.

This means you need to EDIT the "getRawKey" method in SimpleCrypto.java and change:

SecureRandom.getInstance("SHA1PRNG");

to

SecureRandom.getInstance("SHA1PRNG", "Crypto");

Besides this, you can also make your code to choose the best supported key length in your device by adding few more try-catch blocks around.

This means you need to EDIT the "getRawKey" method in SimpleCrypto.java and change:

kgen.init(128,sr); // 196 and 256 may not be available

to

try { kgen.init(256, sr); } catch (Exception e) { // Log.w(LOG, "This device doesn't support 256 bits, trying 192 bits."); try { kgen.init(192, sr); } catch (Exception e1) { // Log.w(LOG, "This device doesn't support 192 bits, trying 128 bits."); kgen.init(128, sr); } }

I hope the code gets updated.

Regards.