Bonsoir,j'ai un problème au moment de décryptage d'un fichier.voila mon code
package application;
voila l'exeption
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class DecrypBlowfish { private static String strkey ="Blowfish"; private static Base64 base64 = new Base64(true); //encrypt using blowfish algorithm public static byte[] encrypt(byte[] Data)throws Exception{ SecretKeySpec key = new SecretKeySpec(strkey.getBytes("UTF8"), "Blowfish"); Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.ENCRYPT_MODE, key); return base64.encode(Data); } //decrypt using blow fish algorithm public static byte[] decrypt(byte[] encrypted)throws Exception{ byte[] encryptedData = base64.decodeBase64(encrypted); SecretKeySpec key = new SecretKeySpec(strkey.getBytes("UTF8"), "Blowfish"); Cipher cipher = Cipher.getInstance("Blowfish"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decrypted = cipher.doFinal(encryptedData); return decrypted; } private static String LireString() { String ligne_lue=null; try{ InputStreamReader lecteur=new InputStreamReader(System.in); BufferedReader entree=new BufferedReader(lecteur); ligne_lue=entree.readLine(); } catch(IOException err){ System.exit(0); } return ligne_lue; } public static void main(String[] args) throws Exception { String fichier; System.out.println("Donner le nom du fichier a decrypter: "); fichier = LireString(); File f = new File(fichier); byte[] tab =java.nio.file.Files.readAllBytes(f.toPath()); byte[] decoded = decrypt(tab); FileWriter fw = new FileWriter("bh.txt",true); fw.write(new String(decoded)); fw.close(); } }
Pouvez vous m'aider?Exception in thread "main" javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:750)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
at com.sun.crypto.provider.BlowfishCipher.engineDoFinal(BlowfishCipher.java:319)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at application.DecrypBlowfish.decrypt(DecrypBlowfish.java:38)
at application.DecrypBlowfish.main(DecrypBlowfish.java:61)
Partager