package net.tasksnow.util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** * @author D056943 * @since 14:48:17 - 18.12.2012 * @project cFoldersService */ public class StringUtils { // =========================================================== // Constants // =========================================================== // =========================================================== // Constructors // =========================================================== private StringUtils() { } // =========================================================== // Methods // =========================================================== public static final String Sha1(final String s) { try { MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); StringBuffer hexString = new StringBuffer(); for (byte element : messageDigest) { String h = Integer.toHexString(0xFF & element); while (h.length() < 2) { h = "0" + h; } hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; } public static String convertStreamToString(java.io.InputStream is) { java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } }