Java SHA1 sha1(String data)

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

Description

sha

License

Open Source License

Declaration

public static String sha1(String data) throws NoSuchAlgorithmException 

Method Source Code


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

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String sha1(String data) throws NoSuchAlgorithmException {
        return byte2hex(MessageDigest.getInstance("SHA-1").digest(data.getBytes()));
    }/*  w  ww.  ja  v  a2s  . c o m*/

    public static String byte2hex(byte[] bytes) {
        BigInteger bi = new BigInteger(1, bytes);
        String hex = bi.toString(16);
        int paddingLength = (bytes.length * 2) - hex.length();
        if (paddingLength > 0) {
            return String.format("%0" + paddingLength + "d", 0) + hex;
        }
        return hex;
    }
}

Related

  1. SHA1(MessageDigest messageDigest, String... texts)
  2. sha1(Object object)
  3. sha1(String data)
  4. sha1(String data)
  5. sha1(String data)
  6. SHA1(String decript)
  7. sha1(String input)
  8. sha1(String input)
  9. sha1(String input)