Bonjour, j'essaye de hasher un mot de passe,avec l'algorithme DES,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
String ss = "toto";
 byte[] plainText = ss.getBytes();
 KeyGenerator keyGen = KeyGenerator.getInstance("DES");
 keyGen.init(56);
 Key key = keyGen.generateKey();
 Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
 cipher.init(Cipher.ENCRYPT_MODE, key);
 byte[] cipherText = cipher.doFinal(plainText);
 System.out.println(new String(cipherText, "UTF8"));
Je récupere le toto codé (par exemple) ØÖÆd‚—Jh
pour décoder
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
String ss = "ØÖÆd‚—Jh";
byte[] plainText = ss.getBytes();
System.out.println("\nStart generating DES key");
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
keyGen.init(56);
Key key = keyGen.generateKey();
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] newPlainText = cipher.doFinal(plainText);
J'ai une exception :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly padded

Je dois faire une grosse erreur mais je ne vois pas ou
merci