Here you can find the source of generateHash(String tcString)
Parameter | Description |
---|---|
tcString | the string to hash |
public static String generateHash(String tcString)
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**//from w w w. ja v a2s .c o m * Generates a SHA-1 hashcode from the input * @param tcString the string to hash * @return the generated hashcode */ public static String generateHash(String tcString) { try { MessageDigest loMD = MessageDigest.getInstance("SHA1"); loMD.reset(); byte[] laBuffer = tcString.getBytes(); loMD.update(laBuffer); byte[] laDigest = loMD.digest(); StringBuffer loReturn = new StringBuffer(""); for (int i = 0, lnLength = laDigest.length; i < lnLength; i++) { loReturn.append(Integer.toString((laDigest[i] & 0xff) + 0x100, 16).substring(1)); } return loReturn.toString(); } catch (NoSuchAlgorithmException ex) { // SHA1 is built in so this will not happen } return ""; } }