Java tutorial
//package com.java2s; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String getHash(String input) { if (input == null || input.equals("") || input.isEmpty()) { return ""; } try { MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] messageDigest = md.digest(input.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { sb.append(Integer.toString((messageDigest[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return ""; } } }