Android SHA1 Hash Create SHA1(String text)

Here you can find the source of SHA1(String text)

Description

SHA

License

Open Source License

Declaration

private static String SHA1(String text) throws NoSuchAlgorithmException 

Method Source Code

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

public class Main {
    private static final String HEX_DIGITS = "0123456789abcdef";

    private static String SHA1(String text) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-1");

        byte[] sha1hash = new byte[40];
        md.update(text.getBytes());/*from   w  ww . j av a  2 s . co m*/
        sha1hash = md.digest();

        return convertToHex(sha1hash);
    }

    private static String convertToHex(byte[] raw) {
        final StringBuilder hex = new StringBuilder(raw.length * 2);

        for (final byte b : raw) {
            hex.append(HEX_DIGITS.charAt((b & 0xF0) >> 4)).append(
                    HEX_DIGITS.charAt((b & 0x0F)));
        }

        return hex.toString();
    }
}

Related

  1. SHA1(String str)
  2. sha512(String what_to_encode)
  3. dataDigest(String in)
  4. SHA1(String s)
  5. SHA1(String text)
  6. SHA256(String text)