Java SHA1 sha1(String str)

Here you can find the source of sha1(String str)

Description

Calculate a SHA-1 hash from the specified string.

License

Open Source License

Parameter

Parameter Description
str String to hash.

Return

SHA-1 hash for string.

Declaration

public static byte[] sha1(String str) 

Method Source Code

//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);
        }
    }
}

Related

  1. SHA1(String str)
  2. SHA1(String str)
  3. sha1(String str)
  4. sha1(String str)
  5. sha1(String str)
  6. sha1(String str)
  7. sha1(String str)
  8. sha1(String str)
  9. sha1(String str)