Java SHA1 sha1(String str)

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

Description

sha

License

Open Source License

Declaration

public static String sha1(String str) 

Method Source Code


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

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String sha1(String str) {
        try {/*from  w ww . j a v a2s  .c om*/
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] bytes = md.digest(str.getBytes("utf-8"));
            StringBuilder sb = new StringBuilder(bytes.length * 2);
            for (int i = 0; i < bytes.length; i++) {
                sb.append(String.format("%02x", bytes[i]));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new InternalError();
        } catch (UnsupportedEncodingException e) {
            throw new InternalError();
        }
    }
}

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 string)