Ajouter un commentaire

aurelbobol6
cryptage/décryptage fichier

Bonjour, voila j'ai fais un petit programme pour copier deux fichiers. J'ai un fichier "original.exe" et je le crypte en "originalCrypte.exe", jusque la tout vas bien, la copie s'est bien déroulée.. mais lorsque je souhaite décrypter mon fichier "originalCrypte.exe" pour le copier à "originalNouveau.exe", j'ai un BadPaddingException qui se passe et je ne sais aps trop quoi faire.
J'ai fais quelques recherche a ce sujet et j'ai vu qu'il fallait utiliser il me semble cipher.getBlockSize() et cipher.getOutputSize(arg0) mais je n'ai pas tout compris.
Autre petit détail, mon fichier original fait 5,02Mo, le originalCrypte fait 5,06Mo et le fichier originalNouveau 5,10Mo.
Je vous ai laissé mon code, si quelqu'un peut m'aider, ce serait vraiment sympa et super arrangeant. Merci d'avance

import ....

public class TestClass {
private static Cipher cipherCrypt = null;
private static Cipher cipherDecrypt = null;
private static SecretKey key = null;

public static void main(String[] args) {
try {
byte[] cle = (new String("password")).getBytes(); // 24 caractères
key = new SecretKeySpec(cle, "Blowfish");
cipherCrypt = Cipher.getInstance("Blowfish");
cipherDecrypt = Cipher.getInstance("Blowfish");
cipherCrypt.init(Cipher.ENCRYPT_MODE, key);
cipherDecrypt.init(Cipher.DECRYPT_MODE, key);

start("c:/temp/original.exe", "c:/temp/originalCrypte.exe", cipherCrypt);
start("c:/temp/originalCrypte.exe", "c:/temp/originalNouveau.exe", cipherCrypt);
}catch(Exception e) {
e.printStackTrace();
}
}

private static void start(String entree, String sortie, Cipher cipher) throws IOException, IllegalBlockSizeException, BadPaddingException
{
byte[] input ;
FileInputStream fIn = new FileInputStream(entree);
FileOutputStream fOut = new FileOutputStream(sortie);
FileChannel canalIn = fIn.getChannel();
FileChannel canalOut = fOut.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(1024);
int nombreLu = 0;
while (nombreLu != -1) {
buffer.clear();
nombreLu = canalIn.read(buffer);
if (nombreLu !=-1) {
buffer.flip();
input = cipherCrypt.doFinal(buffer.array());
canalOut.write(ByteBuffer.wrap(input));
}
}
canalIn.close();
canalOut.close();
fIn.close();
fOut.close();
}
}

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
 L      AA   ZZZZZ   CCC  BBBB  
L A A Z C B B
L AAAA Z C BBBB
L A A Z C B B
LLLL A A ZZZZZ CCC BBBB