Java SHA1 sha1(String value)

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

Description

sha

License

Apache License

Declaration

public static String sha1(String value) 

Method Source Code

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

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static final char[] LETTERS = "0123456789ABCDEF".toCharArray();

    public static String sha1(String value) {
        try {//  w  w  w .  ja v a2  s .  c o m
            return hash(MessageDigest.getInstance("SHA1"), value);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static String hash(MessageDigest digest, String src) {
        return toHexString(digest.digest(src.getBytes()));
    }

    private static String toHexString(byte[] bytes) {
        char[] values = new char[bytes.length * 2];
        int i = 0;
        for (byte b : bytes) {
            values[i++] = LETTERS[((b & 0xF0) >>> 4)];
            values[i++] = LETTERS[b & 0xF];
        }
        return String.valueOf(values);
    }
}

Related

  1. SHA1(String text)
  2. sha1(String text)
  3. SHA1(String texto)
  4. sha1(String txt)
  5. sha1(String utf8)
  6. sha1(String value)
  7. sha12String(MessageDigest messageDigest)
  8. sha1_b64(final String text)
  9. SHA1_HEX(byte[] bytes)