Hi all,
I have written a File Encryption application for android, i am using
AES 256 bit encryption, encryption process is working good, but while
decrypting the files program giving exception as
javax.crypto.BadPaddingException : Pad block corrupted.
i am not able to understand why this exception is coming, even on
internet no proper explanation is given why this exception comes and
how to solve this problem?
please help me, i am giving my decryption code please check if i am
doing something wrong..
Decryption Process Code:
public void decrypt(ArrayList <File> decList, String pass)
{
long total = totalSpaceDecrypt(decList);
// Decryption Code goes here
try
{
System.out.println("Total size of ArrayList: " +total +
"Bytes");
for(File f: decList)
{
FileOutputStream fout;
OutputStream out;
InputStream in;
file = new File(f.getAbsolutePath()); //
/mnt/sdcard/abc.txt
abpath = file.getAbsolutePath();
String dir = abpath.substring(0,
abpath.lastIndexOf("/")); // /mnt/
sdcard
System.out.println("Current Directory:" +dir);
String name = file.getName();
// abc.txt
System.out.println("File name is :" +name);
String name1 = name.substring(0,
name.lastIndexOf(".")); // abc
System.out.println("File name is :" + name1);
//abc
filetemp = new File(dir + "/" + name1 +".tmp");
// /mnt/sdcard/
abc.tmp
// Creating a PBE Key Specification
// Providing the passphrase,salt,iteration
count and key length
kspec = new
PBEKeySpec(pass.toCharArray(),salt,iterations,keylen);
// Locate a PBE Secret Key Factory
factory =
SecretKeyFactory.getInstance("PBEWITHSHAAND256BITAES-CBC-
BC");
// Generate the secret key from the PBEKeySpec
key = factory.generateSecret(kspec);
// Locating a PBE Cipher
cipher =
Cipher.getInstance("AES/CBC/PKCS5Padding");
// Initializing the cipher for encryption
cipher.init(Cipher.DECRYPT_MODE, key);
in = new FileInputStream(file);
// /mnt/sdcard/abc.txt
fout = new FileOutputStream(filetemp); //
/mnt/sdcard/abc.tmp
out = new CipherOutputStream(fout,cipher);
int num = 0;
while((num = in.read(buffer)) >= 0)
{
byte[] decode = cipher.doFinal(buffer);
out.write(decode,0,num);
}
filetemp.renameTo(file);
in.close();
out.close();
fout.close();
}
}
Thanks
Chandra
catch (Exception e)
{
e.printStackTrace();
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en