Java SHA1 sha1(String input)

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

Description

sha

License

Apache License

Declaration

public static String sha1(String input) 

Method Source Code

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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;

public class Main {
    public static String sha1(String input) {
        MessageDigest sha1;/*w w w . j  av a2 s.c  o m*/
        try {
            sha1 = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
        //not sure what encoding is used in input..
        byte[] ret = sha1.digest(input.getBytes());
        return byteArray2Hex(ret);
    }

    private static String byteArray2Hex(byte[] hash) {
        Formatter formatter = new Formatter();
        for (byte b : hash) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    }
}

Related

  1. sha1(String input)
  2. sha1(String input)
  3. sha1(String input)
  4. sha1(String input)
  5. sha1(String input)
  6. sha1(String input)
  7. sha1(String input)
  8. sha1(String input, String encoding)
  9. sha1(String message)