Here you can find the source of sha1(String s)
public static String sha1(String s)
//package com.java2s; /*//from w w w .ja v a2 s . c o m * utils-java8 * Copyright (C) 2014 Raffaele Ragni * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static final String DIGEST_SHA1 = "SHA1"; public static String sha1(String s) { return digest(s, DIGEST_SHA1); } public static String digest(String source, String algorythm) { if (source == null || source.length() == 0) { return source; } try { StringBuilder result = new StringBuilder(); MessageDigest md = MessageDigest.getInstance(algorythm); byte[] bytes = md.digest(source.getBytes("UTF-8")); for (byte b : bytes) { String bb = "0" + Integer.toHexString(b); result.append(bb.substring(bb.length() - 2)); } return result.toString(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { return null; } } }