Bonjour,
J'ai besoin de décrypter une chaine après avoir crypté en 1er lieu.
J'ai cherché sur le net mais j'ai pas trouvé une chose satisfaisante.
Je travaille en java 1.4.
Ci dessous ma méthode de cryptage :
Merci d'avance.
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 public static String sha256(String string){ String ret = ""; byte[] defaultBytes = string.getBytes(); try{ MessageDigest algorithm = MessageDigest.getInstance("SHA-256"); algorithm.reset(); algorithm.update(defaultBytes); byte messageDigest[] = algorithm.digest(); StringBuffer hexString = new StringBuffer(); for (int i=0;i<messageDigest.length;i++) { String hex = Integer.toHexString(0xFF & messageDigest[i]); if(hex.length()==1) hexString.append('0'); hexString.append(hex); } ret = hexString+""; }catch(NoSuchAlgorithmException nsae){ } return ret; }
Partager