Here you can find the source of sha1(String str)
Parameter | Description |
---|---|
str | String to hash. |
public static byte[] sha1(String str)
//package com.java2s; /***************************************************************************** * /*from w w w.ja va2 s. c om*/ * Copyright (C) Zenoss, Inc. 2010, all rights reserved. * * This content is made available according to terms specified in * License.zenoss under the directory where your Zenoss product is installed. * ****************************************************************************/ import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /** * Calculate a SHA-1 hash from the specified string. * * @param str * String to hash. * @return SHA-1 hash for string. */ public static byte[] sha1(String str) { try { MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); return sha1.digest(str.getBytes(Charset.forName("UTF-8"))); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Must support SHA-1", e); } } }