Here you can find the source of digest(String token)
public static String digest(String token) throws GeneralSecurityException, IOException
//package com.java2s; /********************************************************************************** * $URL$//from w ww .j a va2 s .com * $Id$ *********************************************************************************** * * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 The Sakai Foundation * * Licensed under the Educational Community License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.opensource.org/licenses/ECL-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * **********************************************************************************/ import java.io.IOException; import java.security.GeneralSecurityException; import java.security.MessageDigest; public class Main { public static String digest(String token) throws GeneralSecurityException, IOException { MessageDigest sha1 = MessageDigest.getInstance("SHA1"); return byteArrayToHexStr(sha1.digest(token.getBytes("UTF-8"))); } private static String byteArrayToHexStr(byte[] data) { char[] chars = new char[data.length * 2]; for (int i = 0; i < data.length; i++) { byte current = data[i]; int hi = (current & 0xF0) >> 4; int lo = current & 0x0F; chars[2 * i] = (char) (hi < 10 ? ('0' + hi) : ('A' + hi - 10)); chars[2 * i + 1] = (char) (lo < 10 ? ('0' + lo) : ('A' + lo - 10)); } return new String(chars); } }