Java SHA1 sha1(String str)

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

Description

sha

License

Apache License

Declaration

public static String sha1(String str) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.MessageDigest;

public class Main {
    public static String sha1(String str) throws Exception {
        MessageDigest sha = MessageDigest.getInstance("SHA");

        sha.update(str.getBytes("utf8"));
        byte[] bytes = sha.digest();
        StringBuilder ret = new StringBuilder(bytes.length << 1);
        for (int i = 0; i < bytes.length; i++) {
            ret.append(Character.forDigit((bytes[i] >> 4) & 0xf, 16));
            ret.append(Character.forDigit(bytes[i] & 0xf, 16));
        }//  w  w w  .  ja va 2s  .  com
        return ret.toString();
    }
}

Related

  1. sha1(String src)
  2. sha1(String srcStr)
  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)