Here you can find the source of sha1(Object object)
Originally from http://www.velocityreviews.com/forums/t131917-sha1-hash-generator-in-hex.html
Parameter | Description |
---|---|
object | a parameter |
public static String sha1(Object object) throws Exception
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**// ww w. j ava2 s .co m * Originally from * http://www.velocityreviews.com/forums/t131917-sha1-hash-generator-in-hex.html * * @param object * @return */ public static String sha1(Object object) throws Exception { if (object == null) { throw new Exception("Object is null."); } String input = String.valueOf(object); MessageDigest md; try { md = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException ex) { return null; } md.reset(); byte[] buffer = input.getBytes(); md.update(buffer); byte[] digest = md.digest(); String hexStr = ""; for (int i = 0; i < digest.length; i++) { hexStr += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1); } return hexStr; } }