Java SHA1 sha1(String text)

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

Description

sha

License

Open Source License

Declaration

public static String sha1(String text) throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String sha1(String text) throws NoSuchAlgorithmException {
        MessageDigest sha1 = MessageDigest.getInstance("SHA1");
        byte[] digest = sha1.digest((text).getBytes());
        return bytes2String(digest);
    }/*from   ww w.  ja  v a2  s  .  c  om*/

    public static String bytes2String(byte[] bytes) {
        StringBuilder string = new StringBuilder();
        for (byte b : bytes) {
            String hexString = Integer.toHexString(0x00FF & b);
            string.append(hexString.length() == 1 ? "0" + hexString : hexString);
        }
        return string.toString();
    }
}

Related

  1. sha1(String string)
  2. sha1(String string)
  3. SHA1(String strs)
  4. sha1(String text)
  5. SHA1(String text)
  6. SHA1(String text)
  7. SHA1(String text)
  8. SHA1(String text)
  9. sha1(String text)