Acceptor { public String encode(final String str) { String hash = "hash SHA-512 invalide"; MessageDigest digest = null; try { digest = MessageDigest.getInstance("SHA-512"); } catch (NoSuchAlgorithmException e1) { System.out.println(">>Algorithme SHA-512 inconnu"); e1.printStackTrace(); } InputStream is = null; try { is = new ByteArrayInputStream(str.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } final byte[] buffer = new byte[8192]; int read = 0; try { while ((read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } final byte[] shasum = digest.digest(); final BigInteger bigInt = new BigInteger(1, shasum); hash = bigInt.toString(16); } catch (IOException e) { throw new RuntimeException(">>Impossible d'appliquer l'algorithme SHA-512", e); } finally { try { is.close(); } catch (IOException e) { throw new RuntimeException(">>Impossible de fermer le flux d'entree pour le calcul SHA-512", e); } } return hash; } private  Acceptor(); String decode(final String jeton); boolean enregistre(final String jeton); boolean retire(final String jeton); boolean accept(final String jeton); static Acceptor getInstance(); String encode(final String str);  }
@Test public void testEncode() { final String id = "abcdef"; final String result = this.acceptor.encode(id); assertTrue("L'encodage SHA-512 a echoue", "e32ef19623e8ed9d267f657a81944b3d07adbb768518068e88435745564e8d4150a0a703be2a7d88b61e3d390c2bb97e2d4c311fdc69d6b1267f05f59aa920e7".equals(result)); System.out.println("Resultat : " + result); }