Java SHA1 sha1(String s)

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

Description

sha

License

Open Source License

Declaration

public static String sha1(String s) 

Method Source Code


//package com.java2s;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String sha1(String s) {
        try {//from   ww  w .  ja v a 2s  .  c o m
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(s.getBytes());
            byte messageDigest[] = digest.digest();

            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString((0xFF & messageDigest[i]) | 0x100).substring(1));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            return "";
        }
    }
}

Related

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