class 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();

}