I am trying to Decrypt a file from user key, but while doing decryption im getting
the error i have no idea to solve anyone please help me
javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at com.sun.crypto.provider.SunJCE_f.b(DashoA13..)*
at com.sun.crypto.provider.SunJCE_f.b(DashoA13..)*
try {
FileInputStream fin = new FileInputStream(inputFile);
FileOutputStream fout = new FileOutputStream(f.getAbsolutePath()+"/"+inputFileName.getName());
// Create a key.
byte[] desKeyData = userKey.getBytes();
DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey desKey = keyFactory.generateSecret(desKeySpec);
// Read the initialization vector.
DataInputStream din = new DataInputStream(fin);
System.out.println("DataInputStream-"+din==null);
int ivSize = din.readInt();
byte[] iv = new byte[ivSize];
din.readFully(iv);
IvParameterSpec ivps = new IvParameterSpec(iv);
// Use Data Encryption Standard.
Cipher des = Cipher.getInstance("DES/CBC/PKCS5Padding");
des.init(Cipher.DECRYPT_MODE, desKey, ivps);
byte[] input = new byte[256];
int bytesRead;
while ( (bytesRead= fin.read(input))!=-1) {
byte[] output = des.update(input, 0, bytesRead);
if (output != null) fout.write
(output);
}
byte[] output = des.doFinal();
if (output != null) fout.write(output);
fin.close();
fout.flush();
fout.close();
}
catch (GeneralSecurityException ex) {
ex.printStackTrace();
}
catch (IOException ex) {
System.err.println(ex);
ex.printStackTrace();
}